From 71a8e9248504c1c9251e25150a6b5e044e4697e8 Mon Sep 17 00:00:00 2001 From: Jaehyeon Kim Date: Thu, 15 Feb 2024 23:40:59 +0900 Subject: [PATCH] chore(be): modify problem model to get english informations (#1388) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(be): add eng title, descriptions field to problem model * chore(be): modify seed.ts - seed.ts의 첫 번째 Problem에 영문 설명(html 파일) 추가 * test(be): modify problem object * fix(be): add missing eng-title Co-authored-by: SH9480P --- .../admin/src/contest/contest.service.spec.ts | 7 ++- backend/apps/admin/src/problem/mock/mock.ts | 28 ++++++++-- .../src/problem/dto/problem.response.dto.ts | 5 ++ .../src/problem/dto/problems.response.dto.ts | 3 ++ .../client/src/problem/mock/problem.mock.ts | 14 ++++- .../client/src/problem/problem.repository.ts | 5 ++ .../src/submission/mock/problem.mock.ts | 7 ++- .../problem/1-description-eng.html | 5 ++ .../__fixtures__/problem/1-input-eng.html | 1 + .../__fixtures__/problem/1-output-eng.html | 1 + .../migration.sql | 6 +++ backend/prisma/schema.prisma | 53 +++++++++++-------- backend/prisma/seed.ts | 13 +++++ 13 files changed, 118 insertions(+), 30 deletions(-) create mode 100644 backend/prisma/__fixtures__/problem/1-description-eng.html create mode 100644 backend/prisma/__fixtures__/problem/1-input-eng.html create mode 100644 backend/prisma/__fixtures__/problem/1-output-eng.html create mode 100644 backend/prisma/migrations/20240215062711_add_english_information_to_problem_model/migration.sql diff --git a/backend/apps/admin/src/contest/contest.service.spec.ts b/backend/apps/admin/src/contest/contest.service.spec.ts index 4b6f0f4ca9..dbae161dd2 100644 --- a/backend/apps/admin/src/contest/contest.service.spec.ts +++ b/backend/apps/admin/src/contest/contest.service.spec.ts @@ -117,7 +117,12 @@ const problem: Problem = { outputExamples: ['input'], submissionCount: 0, acceptedCount: 0, - acceptedRate: 0 + acceptedRate: 0, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null, + engTitle: null } const contestProblem: ContestProblem = { diff --git a/backend/apps/admin/src/problem/mock/mock.ts b/backend/apps/admin/src/problem/mock/mock.ts index 12974ba5a4..1ca41543e6 100644 --- a/backend/apps/admin/src/problem/mock/mock.ts +++ b/backend/apps/admin/src/problem/mock/mock.ts @@ -43,7 +43,12 @@ export const problems: Problem[] = [ exposeTime: faker.date.anytime(), inputExamples: [], outputExamples: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null }, { id: 2, @@ -68,7 +73,12 @@ export const problems: Problem[] = [ exposeTime: faker.date.anytime(), inputExamples: [], outputExamples: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null } ] @@ -122,7 +132,12 @@ export const importedProblems: Problem[] = [ exposeTime: faker.date.anytime(), inputExamples: [], outputExamples: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null }, { id: 33, @@ -163,6 +178,11 @@ export const importedProblems: Problem[] = [ exposeTime: faker.date.anytime(), inputExamples: [], outputExamples: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null } ] diff --git a/backend/apps/client/src/problem/dto/problem.response.dto.ts b/backend/apps/client/src/problem/dto/problem.response.dto.ts index a71caf604c..7358b6cbd9 100644 --- a/backend/apps/client/src/problem/dto/problem.response.dto.ts +++ b/backend/apps/client/src/problem/dto/problem.response.dto.ts @@ -9,6 +9,11 @@ export class ProblemResponseDto { @Expose() inputDescription: string @Expose() outputDescription: string @Expose() hint: string + @Expose() engTitle: string + @Expose() engDescription: string + @Expose() engInputDescription: string + @Expose() engOutputDescription: string + @Expose() engHint: string @Expose() languages: Language[] @Expose() timeLimit: number @Expose() memoryLimit: number diff --git a/backend/apps/client/src/problem/dto/problems.response.dto.ts b/backend/apps/client/src/problem/dto/problems.response.dto.ts index 1ac8c3a575..4ff6d56408 100644 --- a/backend/apps/client/src/problem/dto/problems.response.dto.ts +++ b/backend/apps/client/src/problem/dto/problems.response.dto.ts @@ -19,6 +19,9 @@ class Problem { @Expose() title: string + @Expose() + engTitle: string + @Expose() difficulty: Level diff --git a/backend/apps/client/src/problem/mock/problem.mock.ts b/backend/apps/client/src/problem/mock/problem.mock.ts index ec88bd549c..9b5a42614a 100644 --- a/backend/apps/client/src/problem/mock/problem.mock.ts +++ b/backend/apps/client/src/problem/mock/problem.mock.ts @@ -32,7 +32,12 @@ export const problems: Problem[] = [ inputExamples: [], outputExamples: [], template: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null }, { id: 2, @@ -57,7 +62,12 @@ export const problems: Problem[] = [ inputExamples: [], outputExamples: [], template: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null } ] diff --git a/backend/apps/client/src/problem/problem.repository.ts b/backend/apps/client/src/problem/problem.repository.ts index a7b1c52c5a..1815aed2fc 100644 --- a/backend/apps/client/src/problem/problem.repository.ts +++ b/backend/apps/client/src/problem/problem.repository.ts @@ -22,6 +22,7 @@ export class ProblemRepository { private readonly problemsSelectOption = { id: true, title: true, + engTitle: true, exposeTime: true, difficulty: true, acceptedRate: true, @@ -34,6 +35,10 @@ export class ProblemRepository { inputDescription: true, outputDescription: true, hint: true, + engDescription: true, + engInputDescription: true, + engOutputDescription: true, + engHint: true, languages: true, timeLimit: true, memoryLimit: true, diff --git a/backend/apps/client/src/submission/mock/problem.mock.ts b/backend/apps/client/src/submission/mock/problem.mock.ts index 51c776a1a1..904cfbae3d 100644 --- a/backend/apps/client/src/submission/mock/problem.mock.ts +++ b/backend/apps/client/src/submission/mock/problem.mock.ts @@ -33,6 +33,11 @@ export const problems: Problem[] = [ updateTime: faker.date.past(), inputExamples: [], outputExamples: [], - isVisible: true + isVisible: true, + engTitle: null, + engDescription: null, + engHint: null, + engInputDescription: null, + engOutputDescription: null } ] diff --git a/backend/prisma/__fixtures__/problem/1-description-eng.html b/backend/prisma/__fixtures__/problem/1-description-eng.html new file mode 100644 index 0000000000..e0c31f47b8 --- /dev/null +++ b/backend/prisma/__fixtures__/problem/1-description-eng.html @@ -0,0 +1,5 @@ +

+ Write a program that takes two integers, A and B, as input and outputs their + sum, A+B. A and B are given in the first line. (0 < A, B < 10) Output the sum + A+B on the first line. +

diff --git a/backend/prisma/__fixtures__/problem/1-input-eng.html b/backend/prisma/__fixtures__/problem/1-input-eng.html new file mode 100644 index 0000000000..426fec4fab --- /dev/null +++ b/backend/prisma/__fixtures__/problem/1-input-eng.html @@ -0,0 +1 @@ +

A and B are given in the first line. (0 < A, B < 10)

diff --git a/backend/prisma/__fixtures__/problem/1-output-eng.html b/backend/prisma/__fixtures__/problem/1-output-eng.html new file mode 100644 index 0000000000..9850a74624 --- /dev/null +++ b/backend/prisma/__fixtures__/problem/1-output-eng.html @@ -0,0 +1 @@ +

Output the sum A+B on the first line.

diff --git a/backend/prisma/migrations/20240215062711_add_english_information_to_problem_model/migration.sql b/backend/prisma/migrations/20240215062711_add_english_information_to_problem_model/migration.sql new file mode 100644 index 0000000000..657787d109 --- /dev/null +++ b/backend/prisma/migrations/20240215062711_add_english_information_to_problem_model/migration.sql @@ -0,0 +1,6 @@ +-- AlterTable +ALTER TABLE "problem" ADD COLUMN "eng_description" TEXT, +ADD COLUMN "eng_hint" TEXT, +ADD COLUMN "eng_input_description" TEXT, +ADD COLUMN "eng_output_description" TEXT, +ADD COLUMN "eng_title" TEXT; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 0bbcd72ae6..fa79fe6dc0 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -138,17 +138,25 @@ model Notice { } model Problem { - id Int @id @default(autoincrement()) - createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull) - createdById Int? @map("created_by_id") - group Group @relation(fields: [groupId], references: [id]) - groupId Int @map("group_id") + id Int @id @default(autoincrement()) + createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull) + createdById Int? @map("created_by_id") + group Group @relation(fields: [groupId], references: [id]) + groupId Int @map("group_id") + title String description String - inputDescription String @map("input_description") - outputDescription String @map("output_description") + inputDescription String @map("input_description") + outputDescription String @map("output_description") hint String - isVisible Boolean @default(true) @map("is_visible") + + // 문제 정보의 영어 버전 제공은 선택사항임 + engTitle String? @map("eng_title") + engDescription String? @map("eng_description") + engInputDescription String? @map("eng_input_description") + engOutputDescription String? @map("eng_output_description") + engHint String? @map("eng_hint") + /// template code item structure /// { /// "lanaguage": Language, @@ -158,20 +166,21 @@ model Problem { /// "locked": boolean /// }[] /// } - template Json[] - languages Language[] - timeLimit Int @map("time_limit") // unit: MilliSeconds - memoryLimit Int @map("memory_limit") // unit: MegaBytes - difficulty Level - source String - submissionCount Int @default(0) @map("submission_count") - acceptedCount Int @default(0) @map("accepted_count") - acceptedRate Float @default(0) @map("accepted_rate") - exposeTime DateTime @default(now()) @map("expose_time") - createTime DateTime @default(now()) @map("create_time") - updateTime DateTime @updatedAt @map("update_time") - inputExamples String[] @map("input_examples") - outputExamples String[] @map("output_examples") + isVisible Boolean @default(true) @map("is_visible") + template Json[] + languages Language[] + timeLimit Int @map("time_limit") // unit: MilliSeconds + memoryLimit Int @map("memory_limit") // unit: MegaBytes + difficulty Level + source String + submissionCount Int @default(0) @map("submission_count") + acceptedCount Int @default(0) @map("accepted_count") + acceptedRate Float @default(0) @map("accepted_rate") + exposeTime DateTime @default(now()) @map("expose_time") + createTime DateTime @default(now()) @map("create_time") + updateTime DateTime @updatedAt @map("update_time") + inputExamples String[] @map("input_examples") + outputExamples String[] @map("output_examples") problemTestcase ProblemTestcase[] problemTag ProblemTag[] diff --git a/backend/prisma/seed.ts b/backend/prisma/seed.ts index 5a704b3e5e..4f1f62d952 100644 --- a/backend/prisma/seed.ts +++ b/backend/prisma/seed.ts @@ -598,21 +598,34 @@ const createProblems = async () => { await prisma.problem.create({ data: { title: '정수 더하기', + engTitle: 'Integer Addition', createdById: superAdminUser.id, groupId: publicGroup.id, description: await readFile( join(fixturePath, 'problem/1-description.html'), 'utf-8' ), + engDescription: await readFile( + join(fixturePath, 'problem/1-description-eng.html'), + 'utf-8' + ), difficulty: Level.Level1, inputDescription: await readFile( join(fixturePath, 'problem/1-input.html'), 'utf-8' ), + engInputDescription: await readFile( + join(fixturePath, 'problem/1-input-eng.html'), + 'utf-8' + ), outputDescription: await readFile( join(fixturePath, 'problem/1-output.html'), 'utf-8' ), + engOutputDescription: await readFile( + join(fixturePath, 'problem/1-output-eng.html'), + 'utf-8' + ), languages: [Language.C, Language.Cpp, Language.Java, Language.Python3], hint: '', timeLimit: 2000,