Skip to content

Commit

Permalink
fix: createSubmissionDto에 languageId 저장하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yechan2468 committed Mar 5, 2024
1 parent 7e7a432 commit 1185243
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
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;

@IsNotEmpty()
competitionId: number;

@IsNotEmpty()
language: keyof typeof LANGUAGES;

@IsNotEmpty()
code: string;

toEntity(problem: Problem, user: User): Submission {
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;
Expand Down
16 changes: 16 additions & 0 deletions be/algo-with-me-api/src/problem/language.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1185243

Please sign in to comment.