Ajout démarrage et fin de partie
This commit is contained in:
@ -1,19 +1,63 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common'
|
||||
import { Controller, Delete, Get, HttpCode, Post, UseGuards } from '@nestjs/common'
|
||||
import { GameService } from './game.service'
|
||||
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'
|
||||
import { ApiBearerAuth, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger'
|
||||
import { ApiBearerAuth, ApiNoContentResponse, ApiOkResponse, ApiOperation, ApiUnauthorizedResponse } from '@nestjs/swagger'
|
||||
import { GameEntity } from './entities/game.entity'
|
||||
|
||||
@Controller('game')
|
||||
export class GameController {
|
||||
constructor(private readonly gameService: GameService) {}
|
||||
|
||||
/**
|
||||
* Récupérer l'objet du jeu
|
||||
*
|
||||
* @throws {401} Non authentifié⋅e
|
||||
*/
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOkResponse({ type: GameEntity })
|
||||
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
|
||||
async find() {
|
||||
async find(): Promise<GameEntity> {
|
||||
return new GameEntity(await this.gameService.find())
|
||||
}
|
||||
|
||||
/**
|
||||
* Démarrer le jeu
|
||||
* @remarks Lance le jeu, tire au sort læ joueur⋅se de départ et donne un solde initial pour acheter des trains. Le jeu ne doit pas être déjà démarré.
|
||||
*
|
||||
* @throws {401} Non authentifié⋅e
|
||||
* @throws {409} La partie est déjà démarrée
|
||||
*/
|
||||
@Post('/start')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
async start(): Promise<GameEntity> {
|
||||
return new GameEntity(await this.gameService.start())
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrêter le jeu
|
||||
* @remarks Arrête le jeu (si déjà lancé), à n'utiliser qu'en fin de partie.
|
||||
*
|
||||
* @throws {401} Non authentifié⋅e
|
||||
* @throws {409} La partie n'est pas démarrée
|
||||
*/
|
||||
@Post('/stop')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
async stop(): Promise<GameEntity> {
|
||||
return new GameEntity(await this.gameService.stop())
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialiser le jeu
|
||||
* @remarks Réinitialise toutes les données de jeu, supprimant les trains parcourus et les défis accomplis. À utiliser avec précaution.
|
||||
*
|
||||
* @throws {401} Non authentifié⋅e
|
||||
*/
|
||||
@Delete('/reset')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
async reset(): Promise<GameEntity> {
|
||||
return new GameEntity(await this.gameService.reset())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user