@@ -2,22 +2,31 @@ import {
22 Body ,
33 Controller ,
44 Get ,
5+ NotFoundException ,
56 Param ,
67 Post ,
8+ Query ,
79 Request ,
810 UseGuards ,
911} from '@nestjs/common' ;
1012import { ApiOkResponse , ApiOperation } from '@nestjs/swagger' ;
1113import { BenchmarkService } from 'src/benchmarks/benchmark.service' ;
1214import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto' ;
15+ import { FindSubmissionIDDTO } from 'src/submissions/dto/find-submission-id.dto' ;
16+ import { FindSubmissionLangDTO } from 'src/submissions/dto/find-submission-lang.dto' ;
17+ import { Submission } from 'src/submissions/submission.entity' ;
18+ import { SubmissionsService } from 'src/submissions/submissions.service' ;
1319import { ValidatedJWTReq } from '../auth/dto/validated-jwt-req' ;
1420import { JwtAuthGuard } from '../auth/jwt-auth.guard' ;
1521import { Benchmark } from './benchmark.entity' ;
1622import { BenchmarkIdDto } from './dto/benchmarkId.dto' ;
1723
1824@Controller ( 'benchmarks' )
1925export class BenchmarkController {
20- constructor ( private readonly benchmarkService : BenchmarkService ) { }
26+ constructor (
27+ private readonly benchmarkService : BenchmarkService ,
28+ private readonly submissionsService : SubmissionsService ,
29+ ) { }
2130
2231 @ApiOperation ( { summary : 'Create a benchmark' } )
2332 @ApiOkResponse ( { type : Benchmark , description : 'Created benchmark' } )
@@ -46,4 +55,28 @@ export class BenchmarkController {
4655 ) : Promise < Benchmark | undefined > {
4756 return this . benchmarkService . findOne ( benchmarkIdDto . id ) ;
4857 }
58+
59+ @ApiOperation ( { summary : 'Get last submission for benchmark + language' } )
60+ @UseGuards ( JwtAuthGuard )
61+ @Get ( ':id/submissions/last' )
62+ async findLastForUserByLanguage (
63+ @Request ( ) req : ValidatedJWTReq ,
64+ @Query ( ) query : FindSubmissionLangDTO ,
65+ @Param ( ) params : FindSubmissionIDDTO ,
66+ ) : Promise < Submission > {
67+ const submission : Submission | undefined =
68+ await this . submissionsService . findLastByLanguage (
69+ {
70+ benchmarkId : params . id ,
71+ language : query . language ,
72+ } ,
73+ req . user ,
74+ ) ;
75+
76+ if ( ! submission ) {
77+ throw new NotFoundException ( ) ;
78+ }
79+
80+ return submission ;
81+ }
4982}
0 commit comments