Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TDT4240 Tank Wars
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
Package 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
Show more breadcrumbs
Snorre Skjellestad Kristiansen
TDT4240 Tank Wars
Commits
1ceaa7a5
Commit
1ceaa7a5
authored
2 years ago
by
Snorre Skjellestad Kristiansen
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Create a highscore endpoint"
parent
10695731
No related branches found
Branches containing commit
No related tags found
1 merge request
!4
Resolve "Create a highscore endpoint"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/documentation.md
+4
-0
4 additions, 0 deletions
backend/documentation.md
backend/src/index.ts
+16
-0
16 additions, 0 deletions
backend/src/index.ts
backend/types/User.ts
+1
-1
1 addition, 1 deletion
backend/types/User.ts
with
21 additions
and
1 deletion
backend/documentation.md
+
4
−
0
View file @
1ceaa7a5
...
...
@@ -19,3 +19,7 @@
> - 409 User already exists
> - 201 User created
### GET /highscores
> - 204 No highscores found
> - 200 List of users with highest score
This diff is collapsed.
Click to expand it.
backend/src/index.ts
+
16
−
0
View file @
1ceaa7a5
import
express
from
'
express
'
;
import
path
from
'
path
'
;
import
{
User
}
from
'
../types/User
'
;
const
app
=
express
();
const
port
=
3000
;
...
...
@@ -85,3 +86,18 @@ app.post('/user/create/:username', async (req, res) => {
res
.
status
(
201
).
send
(
newUserRef
.
id
);
}
});
// returns users with top 10 highscore
app
.
get
(
'
/highscores
'
,
async
(
req
,
res
)
=>
{
const
usersRef
=
admin
.
firestore
().
collection
(
'
users
'
);
const
querySnapshot
=
await
usersRef
.
orderBy
(
'
highscore
'
,
'
desc
'
).
limit
(
10
).
get
();
if
(
querySnapshot
.
empty
)
{
res
.
status
(
204
).
send
(
'
No highscores found
'
);
}
else
{
const
users
=
querySnapshot
.
docs
.
map
((
doc
:
any
)
=>
doc
.
data
()
as
User
);
res
.
status
(
200
).
send
(
users
);
}
})
This diff is collapsed.
Click to expand it.
backend/types/User.ts
+
1
−
1
View file @
1ceaa7a5
type
User
=
{
export
type
User
=
{
id
:
string
;
username
:
string
;
wins
:
number
;
...
...
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