Ajout endpoints tentatives de course
This commit is contained in:
40
server/src/runs/runs.controller.ts
Normal file
40
server/src/runs/runs.controller.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common'
|
||||
import { RunsService } from './runs.service'
|
||||
import { RunEntity } from './entities/run.entity'
|
||||
import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto'
|
||||
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
||||
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'
|
||||
import { ApiBearerAuth } from '@nestjs/swagger'
|
||||
import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils'
|
||||
|
||||
@Controller('runs')
|
||||
export class RunsController {
|
||||
constructor(private readonly runsService: RunsService) {}
|
||||
|
||||
/**
|
||||
* Recherche de tentatives de course
|
||||
*
|
||||
* @throws {401} Non authentifié⋅e
|
||||
*/
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOkResponsePaginated(RunEntity)
|
||||
async findAll(@Query() queryPagination: QueryPaginationDto): Promise<PaginateOutputDto<RunEntity>> {
|
||||
const [runs, total] = await this.runsService.findAll(queryPagination)
|
||||
return paginateOutput<RunEntity>(runs.map(challenge => new RunEntity(challenge)), total, queryPagination)
|
||||
}
|
||||
|
||||
/**
|
||||
* Recherche d'une tentative de course par identifiant
|
||||
*
|
||||
* @throws {401} Non authentifié⋅e
|
||||
* @throws {404} Essai non trouvé
|
||||
*/
|
||||
@Get(':id')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
async findOne(@Param('id') id: number): Promise<RunEntity> {
|
||||
return new RunEntity(await this.runsService.findOne(id))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user