Skip to content

Commit

Permalink
chore(be): modify problem model to get english informations (#1388)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and mnseok committed Feb 26, 2024
1 parent 1ffce5a commit 71a8e92
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 30 deletions.
7 changes: 6 additions & 1 deletion backend/apps/admin/src/contest/contest.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
28 changes: 24 additions & 4 deletions backend/apps/admin/src/problem/mock/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
]

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
]
5 changes: 5 additions & 0 deletions backend/apps/client/src/problem/dto/problem.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions backend/apps/client/src/problem/dto/problems.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Problem {
@Expose()
title: string

@Expose()
engTitle: string

@Expose()
difficulty: Level

Expand Down
14 changes: 12 additions & 2 deletions backend/apps/client/src/problem/mock/problem.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
]

Expand Down
5 changes: 5 additions & 0 deletions backend/apps/client/src/problem/problem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ProblemRepository {
private readonly problemsSelectOption = {
id: true,
title: true,
engTitle: true,
exposeTime: true,
difficulty: true,
acceptedRate: true,
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion backend/apps/client/src/submission/mock/problem.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
5 changes: 5 additions & 0 deletions backend/prisma/__fixtures__/problem/1-description-eng.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>
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.
</p>
1 change: 1 addition & 0 deletions backend/prisma/__fixtures__/problem/1-input-eng.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>A and B are given in the first line. (0 < A, B < 10)</p>
1 change: 1 addition & 0 deletions backend/prisma/__fixtures__/problem/1-output-eng.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Output the sum A+B on the first line.</p>
Original file line number Diff line number Diff line change
@@ -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;
53 changes: 31 additions & 22 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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[]
Expand Down
13 changes: 13 additions & 0 deletions backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 71a8e92

Please sign in to comment.