Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
oetzit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
commul
oetzit
Commits
1ebd42f3
Commit
1ebd42f3
authored
3 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #be sketch shot routes
parent
b7b3ae18
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/src/api.ts
+91
-6
91 additions, 6 deletions
backend/src/api.ts
with
91 additions
and
6 deletions
backend/src/api.ts
+
91
−
6
View file @
1ebd42f3
...
@@ -5,11 +5,45 @@ import { connection } from "./db";
...
@@ -5,11 +5,45 @@ import { connection } from "./db";
// NOTE: see https://www.npmjs.com/package/fastify-plugin for TS plugin definition
// NOTE: see https://www.npmjs.com/package/fastify-plugin for TS plugin definition
const
ParamsSchema
=
Type
.
Object
({
const
Game
ParamsSchema
=
Type
.
Object
({
game_id
:
Type
.
String
({
format
:
"
uuid
"
}),
game_id
:
Type
.
String
({
format
:
"
uuid
"
}),
});
});
type
ParamsType
=
Static
<
typeof
ParamsSchema
>
;
type
GameParamsType
=
Static
<
typeof
GameParamsSchema
>
;
const
ClueParamsSchema
=
Type
.
Object
({
game_id
:
Type
.
String
({
format
:
"
uuid
"
}),
clue_id
:
Type
.
String
({
format
:
"
uuid
"
}),
});
type
ClueParamsType
=
Static
<
typeof
ClueParamsSchema
>
;
const
ClueSchema
=
Type
.
Object
({
id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
game_id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
word_id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
began_at
:
Type
.
Optional
(
Type
.
String
({
format
:
"
date-time
"
})),
ended_at
:
Type
.
Optional
(
Type
.
String
({
format
:
"
date-time
"
})),
});
const
CluePostSchema
=
Type
.
Pick
(
ClueSchema
,
[
"
game_id
"
,
"
word_id
"
]);
const
CluePatchSchema
=
Type
.
Pick
(
ClueSchema
,
[
"
began_at
"
,
"
ended_at
"
]);
type
ClueType
=
Static
<
typeof
ClueSchema
>
;
const
ShotSchema
=
Type
.
Object
({
id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
game_id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
clue_id
:
Type
.
Optional
(
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
}))),
began_at
:
Type
.
String
({
format
:
"
date-time
"
}),
ended_at
:
Type
.
String
({
format
:
"
date-time
"
}),
typed
:
Type
.
String
(),
final
:
Type
.
String
(),
});
const
ShotPostSchema
=
Type
.
Omit
(
ShotSchema
,
[
"
id
"
]);
type
ShotType
=
Static
<
typeof
ShotSchema
>
;
const
GameSchema
=
Type
.
Object
({
const
GameSchema
=
Type
.
Object
({
id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
id
:
Type
.
Readonly
(
Type
.
String
({
format
:
"
uuid
"
})),
...
@@ -58,13 +92,13 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
...
@@ -58,13 +92,13 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
});
});
fastify
.
route
<
{
fastify
.
route
<
{
Params
:
ParamsType
;
Params
:
Game
ParamsType
;
Reply
:
GameType
;
Reply
:
GameType
;
}
>
({
}
>
({
method
:
"
GET
"
,
method
:
"
GET
"
,
url
:
"
/games/:game_id
"
,
url
:
"
/games/:game_id
"
,
schema
:
{
schema
:
{
params
:
ParamsSchema
,
params
:
Game
ParamsSchema
,
response
:
{
response
:
{
200
:
GameSchema
,
200
:
GameSchema
,
404
:
{},
// TODO: JSend error
404
:
{},
// TODO: JSend error
...
@@ -103,14 +137,14 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
...
@@ -103,14 +137,14 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
});
});
fastify
.
route
<
{
fastify
.
route
<
{
Params
:
ParamsType
;
Params
:
Game
ParamsType
;
Body
:
Static
<
typeof
GamePatchSchema
>
;
Body
:
Static
<
typeof
GamePatchSchema
>
;
Reply
:
GameType
;
Reply
:
GameType
;
}
>
({
}
>
({
method
:
"
PATCH
"
,
method
:
"
PATCH
"
,
url
:
"
/games/:game_id
"
,
url
:
"
/games/:game_id
"
,
schema
:
{
schema
:
{
params
:
ParamsSchema
,
params
:
Game
ParamsSchema
,
body
:
GamePatchSchema
,
body
:
GamePatchSchema
,
response
:
{
response
:
{
200
:
GameSchema
,
200
:
GameSchema
,
...
@@ -131,6 +165,57 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
...
@@ -131,6 +165,57 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
},
},
});
});
fastify
.
route
<
{
Params
:
Static
<
typeof
GameParamsSchema
>
;
Body
:
Static
<
typeof
CluePostSchema
>
;
Reply
:
ClueType
;
}
>
({
method
:
"
POST
"
,
url
:
"
/games/:game_id/clues
"
,
schema
:
{
params
:
GameParamsSchema
,
body
:
CluePostSchema
,
response
:
{
200
:
ClueSchema
,
},
},
handler
:
async
(
request
,
reply
)
=>
{},
});
fastify
.
route
<
{
Params
:
Static
<
typeof
ClueParamsSchema
>
;
Body
:
Static
<
typeof
CluePatchSchema
>
;
Reply
:
ClueType
;
}
>
({
method
:
"
PATCH
"
,
url
:
"
/games/:game_id/clues/:clue_id
"
,
schema
:
{
params
:
ClueParamsSchema
,
body
:
CluePatchSchema
,
response
:
{
200
:
ClueSchema
,
},
},
handler
:
async
(
request
,
reply
)
=>
{},
});
fastify
.
route
<
{
Params
:
Static
<
typeof
GameParamsSchema
>
;
Body
:
Static
<
typeof
ShotPostSchema
>
;
Reply
:
ShotType
;
}
>
({
method
:
"
POST
"
,
url
:
"
/games/:game_id/shots
"
,
schema
:
{
params
:
GameParamsSchema
,
body
:
ShotPostSchema
,
response
:
{
200
:
ShotSchema
,
},
},
handler
:
async
(
request
,
reply
)
=>
{},
});
next
();
next
();
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment