diff --git a/backend/src/controllers/highscoreController.ts b/backend/src/controllers/highscoreController.ts index dd508aaea2fb0dc33724db236967c1b150c436ef..cf570faa56b11c7ac0220ea0b57b520360e89f83 100644 --- a/backend/src/controllers/highscoreController.ts +++ b/backend/src/controllers/highscoreController.ts @@ -1,27 +1,13 @@ import { Request, Response } from 'express'; -import { Lobby } from '../models/Lobby'; -import { GameHandler } from '../gameHandler'; -import { getUserById } from '../functions/getUserById'; import { User } from '../../types/User'; -import admin from '../functions/firebaseAdmin'; -import { IGame } from '../interfaces/IGame'; import { getTopUsers } from '../functions/firebaseCache'; -const gameHandler = GameHandler.getInstance(); - export const top10 = async (req: Request, res: Response): Promise<void> => { const topUsers = await getTopUsers(); - if (topUsers === null) { - res.status(204).send('No highscores found'); + if (topUsers) { + res.status(200).send(topUsers); } else { - const users = topUsers.docs.map( - (doc: any) => - ({ - id: doc.id, - ...doc.data(), - } as User) - ); - res.status(200).send(users); + res.status(204).send('No highscores found'); } }; diff --git a/backend/src/functions/firebaseCache.ts b/backend/src/functions/firebaseCache.ts index 18376f41b66f513a02a22ff37a5443aabffc72bc..97ae0068838318af2e2b8325abdfb5badb0312e8 100644 --- a/backend/src/functions/firebaseCache.ts +++ b/backend/src/functions/firebaseCache.ts @@ -58,17 +58,13 @@ export async function getUsersIds(): Promise<any> { * * @returns a list of users */ -export async function getTopUsers(): Promise<any> { +export async function getTopUsers(): Promise<User[] | null> { const usersRef: CollectionReference = admin.firestore().collection('users'); const querySnapshot: Query = usersRef.orderBy('highscore', 'desc').limit(10); const cacheKey = 'topUsers'; const responseMapper = (firestoreResponse: QueryDocumentSnapshot[]) => { return firestoreResponse.map((doc) => { - return { - id: doc.id, - username: doc.data().username, - highscore: doc.data().highscore, - }; + return { ...doc.data } as User; }); }; return retrieveFromCache(querySnapshot, queryCache, cacheKey, responseMapper); diff --git a/backend/src/routes/gameRoutes.ts b/backend/src/routes/gameRoutes.ts index e192fb1d9d01fd554d1498a154a47c789a6b8ecc..d3afad7223ccd44a230f7ced3ef32139a9c33a4d 100644 --- a/backend/src/routes/gameRoutes.ts +++ b/backend/src/routes/gameRoutes.ts @@ -107,7 +107,7 @@ router.post('/:gameid/move', gameController.move); /** * @swagger - * /game/{id}/currentTurn: + * /game/{gameId}/gameState: * post: * tags: [Game] * summary: Check current turn. @@ -171,7 +171,7 @@ router.post('/:gameid/move', gameController.move); * tankType: * type: string */ -router.get('/:gameid/currentTurn', gameController.currentTurn); +router.get('/:gameid/gameState', gameController.currentTurn); /** * @swagger diff --git a/backend/src/routes/lobbyRoutes.ts b/backend/src/routes/lobbyRoutes.ts index 5318f5ee1b5c00da1a47f8b9c50ee11a07d44474..12b81570ab7505aa6f25e78af551fc1f2d67cc44 100644 --- a/backend/src/routes/lobbyRoutes.ts +++ b/backend/src/routes/lobbyRoutes.ts @@ -5,7 +5,7 @@ const router = express.Router(); /** * @swagger - * /lobby/{id}/leave: + * /lobby/{lobbyId}/leave: * post: * tags: [Lobby] * summary: Leaves a lobby. @@ -30,7 +30,7 @@ router.post('/:id/leave', lobbyController.leaveLobby); /** * @swagger - * /lobby/{id}/join: + * /lobby/{lobbyId}/join: * post: * tags: [Lobby] * summary: Joins a lobby.