From 1185243c72e4708c88fc6a2f8eaa0865c91b0e0a Mon Sep 17 00:00:00 2001 From: Yechan Lee Date: Tue, 5 Mar 2024 15:45:27 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20createSubmissionDto=EC=97=90=20languageI?= =?UTF-8?q?d=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/competition/dto/create-submission.dto.ts | 8 ++++++-- .../src/problem/language.enums.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/be/algo-with-me-api/src/competition/dto/create-submission.dto.ts b/be/algo-with-me-api/src/competition/dto/create-submission.dto.ts index a41c252..fb07f14 100644 --- a/be/algo-with-me-api/src/competition/dto/create-submission.dto.ts +++ b/be/algo-with-me-api/src/competition/dto/create-submission.dto.ts @@ -1,10 +1,10 @@ import { IsNotEmpty } from 'class-validator'; import { Problem } from '../../problem/entities/problem.entity'; +import { LANGUAGES, getLanguageIdByName } from '../../problem/language.enums'; +import { User } from '../../user/entities/user.entity'; import { Submission } from '../entities/submission.entity'; -import { User } from '@src/user/entities/user.entity'; - export class CreateSubmissionDto { @IsNotEmpty() problemId: number; @@ -12,6 +12,9 @@ export class CreateSubmissionDto { @IsNotEmpty() competitionId: number; + @IsNotEmpty() + language: keyof typeof LANGUAGES; + @IsNotEmpty() code: string; @@ -19,6 +22,7 @@ export class CreateSubmissionDto { const submission = new Submission(); submission.code = this.code; submission.competitionId = this.competitionId; + submission.languageId = getLanguageIdByName(this.language); submission.problem = problem; submission.user = user; return submission; diff --git a/be/algo-with-me-api/src/problem/language.enums.ts b/be/algo-with-me-api/src/problem/language.enums.ts index 48eda50..f064202 100644 --- a/be/algo-with-me-api/src/problem/language.enums.ts +++ b/be/algo-with-me-api/src/problem/language.enums.ts @@ -3,6 +3,22 @@ export const LANGUAGES = { Python3: 'Python3', } as const; +const LANGUAGE_IDS = { + JavaScript: 1, + Python: 2, +} as const; + +export function getLanguageIdByName(languageName: keyof typeof LANGUAGES) { + if (!(languageName in LANGUAGE_IDS)) { + throw new Error( + `${languageName} 언어는 지원하지 않는 언어입니다. 지원하는 언어: ${Object.keys( + LANGUAGE_IDS, + ).join(', ')}`, + ); + } + return LANGUAGE_IDS[languageName]; +} + interface ILanguageMetadata { oneLineComment: string; indent: string;