1- import { Body , Controller , Get , Post , Request , UseGuards } from '@nestjs/common' ;
1+ import { Body , Controller , Get , Param , Post , Request , UseGuards } from '@nestjs/common' ;
22import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto' ;
33import { BenchmarkService } from 'src/benchmarks/benchmark.service' ;
44import { Benchmark } from './benchmark.entity' ;
55import { JwtAuthGuard } from '../auth/jwt-auth.guard' ;
66import { ValidatedJWTReq } from '../auth/dto/validated-jwt-req' ;
7+ import { ApiBadRequestResponse , ApiOkResponse , ApiOperation } from '@nestjs/swagger' ;
8+ import { BenchmarkIdDto } from './dto/benchmarkId.dto' ;
79
810
911@Controller ( 'benchmarks' )
1012export class BenchmarkController {
1113 constructor ( private readonly benchmarkService : BenchmarkService ) {
1214 }
1315
16+ @ApiOperation ( { summary : 'Create a benchmark' } )
17+ @ApiOkResponse ( { type : Benchmark , description : 'Created benchmark' } )
18+
1419 @Post ( )
1520 @UseGuards ( JwtAuthGuard )
1621 async createBenchmark (
@@ -21,10 +26,21 @@ export class BenchmarkController {
2126 return this . benchmarkService . create ( benchmark , req . user ) ;
2227 }
2328
29+ @ApiOperation ( { summary : 'Get all benchmarks' } )
30+ @ApiOkResponse ( { type : [ Benchmark ] , description : 'Array of benchmarks' } )
2431 @Get ( )
2532 async getEveryBenchMarks ( ) : Promise < Benchmark [ ] > {
2633 return this . benchmarkService . getAll ( ) ;
2734 }
2835
36+ @ApiOperation ( { summary : 'Get benchmark by id' } )
37+ @ApiOkResponse ( { type : Benchmark , description : 'Requested benchmark' } )
38+ @Get ( ':id' )
39+ async getBenchmarkById ( @Param ( ) id : BenchmarkIdDto ) : Promise < Benchmark | undefined > {
40+ const benchmark = await this . benchmarkService . findOne ( id ) ;
41+
42+ return benchmark ;
43+ }
44+
2945
3046}
0 commit comments