Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TDT4240 Tank Wars
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
25da6521
Commit
25da6521
authored
1 year ago
by
Fredrik Fonn Hansen
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "backend highscore and stats"
parent
370f2ab3
No related branches found
Branches containing commit
No related tags found
1 merge request
!62
Resolve "backend highscore and stats"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+4
-4
4 additions, 4 deletions
.gitlab-ci.yml
backend/src/controllers/userController.ts
+40
-0
40 additions, 0 deletions
backend/src/controllers/userController.ts
backend/src/routes/userRoutes.ts
+41
-0
41 additions, 0 deletions
backend/src/routes/userRoutes.ts
with
85 additions
and
4 deletions
.gitlab-ci.yml
+
4
−
4
View file @
25da6521
...
...
@@ -90,7 +90,7 @@ Gradle-build:
-
./gradlew build --refresh-dependencies
-
gradle build
Backend (NTNU-VM)
:
VM Deploy
:
image
:
node:16.10.0
stage
:
deploy
needs
:
[
Typescript-compile
,
API-test
]
...
...
@@ -114,14 +114,14 @@ Backend (NTNU-VM):
VM Heartbeat
:
stage
:
deploy
needs
:
[
Backend (NTNU-VM)
]
needs
:
[
VM Deploy
]
image
:
alpine
script
:
-
apk add --no-cache curl
-
|
for i in {1..18}; do
sleep 10
response=$(curl --silent --write-out "%{http_code}
"
--connect-timeout 5 --max-time 10 http://10.212.26.72/server/heartbeat)
response=$(curl --silent --write-out "%{http_code}
\n" --output /dev/null
--connect-timeout 5 --max-time 10 http://10.212.26.72/server/heartbeat)
echo "Response: $response"
if [ "$response" -eq 200 ]; then
echo "Server is alive"
...
...
@@ -132,4 +132,4 @@ VM Heartbeat:
exit 1
only
:
refs
:
-
main
-
main
\ No newline at end of file
This diff is collapsed.
Click to expand it.
backend/src/controllers/userController.ts
+
40
−
0
View file @
25da6521
...
...
@@ -84,3 +84,43 @@ export const deleteUser = async (req: Request, res: Response): Promise<void> =>
res
.
status
(
404
).
send
(
'
User not found
'
);
}
};
// update highscore
export
const
updateHighscore
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
usersRef
=
admin
.
firestore
().
collection
(
'
users
'
);
const
username
=
req
.
params
.
username
;
const
requestBody
=
req
.
body
;
// check if request body is a valid User object
if
(
requestBody
.
username
===
undefined
||
requestBody
.
highscore
===
undefined
||
requestBody
.
games
===
undefined
||
requestBody
.
wins
===
undefined
||
requestBody
.
losses
===
undefined
)
{
res
.
status
(
400
).
send
(
'
Invalid request body
'
);
}
if
(
username
===
undefined
||
username
===
''
)
{
res
.
status
(
400
).
send
(
'
No username provided
'
);
}
const
user
=
await
getUserById
(
username
);
if
(
user
)
{
// update highscore
const
newUserData
:
Partial
<
User
>
=
{
highscore
:
requestBody
.
highscore
,
games
:
requestBody
.
games
,
wins
:
requestBody
.
wins
,
losses
:
requestBody
.
losses
,
};
log
(
'
firestore: sending request to update score of
'
+
user
.
username
);
await
usersRef
.
doc
(
user
.
id
).
update
(
newUserData
);
res
.
status
(
200
).
send
(
'
Highscore updated
'
);
}
else
{
res
.
status
(
404
).
send
(
'
User not found
'
);
}
};
This diff is collapsed.
Click to expand it.
backend/src/routes/userRoutes.ts
+
41
−
0
View file @
25da6521
...
...
@@ -113,4 +113,45 @@ router.post('/:username', userController.createUser);
*/
router
.
delete
(
'
/:username
'
,
userController
.
deleteUser
);
/**
* @swagger
* /user/{username}/highscore:
* post:
* tags: [User]
* summary: Update the users stats.
* description: Update the users stats.
* parameters:
* - name: username
* in: query
* required: true
* description: Username of the user to update.
* schema:
* type: string
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* username:
* type: string
* wins:
* type: integer
* losses:
* type: integer
* highscore:
* type: integer
* games:
* type: integer
* responses:
* 200:
* description: Score updated.
* 400:
* description: Invalid request.
* 404:
* description: User not found.
*/
router
.
post
(
'
/:username/highscore
'
,
userController
.
updateHighscore
);
export
default
router
;
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