Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(be): merge client problem repository into service #2198

Merged
merged 16 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions apps/backend/apps/admin/src/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
Inject,
Injectable,
InternalServerErrorException

Check warning on line 6 in apps/backend/apps/admin/src/problem/problem.service.ts

View workflow job for this annotation

GitHub Actions / Lint

'InternalServerErrorException' is defined but never used
} from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { Language } from '@generated'
Expand Down Expand Up @@ -57,10 +57,12 @@
'A problem should support at least one language'
)
}
template.forEach((template) => {
if (!languages.includes(template.language)) {

// Check if the problem supports the language in the template
template.forEach((template: Template) => {
if (!languages.includes(template.language as Language)) {
throw new UnprocessableDataException(
`This problem does not support ${template.language}`
`This problem does not support ${template.language as Language}`
)
}
})
Expand Down Expand Up @@ -244,7 +246,7 @@
try {
await this.storageService.uploadImage({
filename: newFilename,
fileSize: fileSize,

Check warning on line 249 in apps/backend/apps/admin/src/problem/problem.service.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected property shorthand
content: createReadStream(),
type: mimetype
})
Expand Down Expand Up @@ -403,9 +405,9 @@
}
const supportedLangs = languages ?? problem.languages
template?.forEach((template) => {
if (!supportedLangs.includes(template.language)) {
if (!supportedLangs.includes(template.language as Language)) {
throw new UnprocessableDataException(
`This problem does not support ${template.language}`
`This problem does not support ${template.language as Language}`
)
}
})
Expand Down Expand Up @@ -677,7 +679,7 @@
* @throws DuplicateFoundException - 이미 존재하는 태그일 경우
*/
async createTag(tagName: string): Promise<Tag> {
// throw error if tag already exists
// 존재하는 태그일 경우 에러를 throw합니다
try {
return await this.prisma.tag.create({
data: {
Expand All @@ -691,7 +693,7 @@
)
throw new DuplicateFoundException('tag')

throw new InternalServerErrorException(error)
throw error
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { CreateTemplateDto } from './create-code-draft.dto'
import type { JsonValue } from '@prisma/client/runtime/library'

export class CodeDraftResponseDto {
userId: string
problemId: string
template: CreateTemplateDto
createTime: string
updateTime: string
userId: number
problemId: number
template: JsonValue
createTime: Date
updateTime: Date
}
39 changes: 32 additions & 7 deletions apps/backend/apps/client/src/problem/dto/problem.response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import {
type Language,
Level,
type ProblemTestcase,
type Tag
} from '@prisma/client'
import type { Language, Level, ProblemTestcase, Tag } from '@prisma/client'
import type { JsonValue } from '@prisma/client/runtime/library'
import { Exclude, Expose } from 'class-transformer'

@Exclude()
export class ProblemResponseDto {
id: number
title: string
description: string
inputDescription: string
outputDescription: string
hint: string
engTitle: string | null
engDescription: string | null
engInputDescription: string | null
engOutputDescription: string | null
engHint: string | null
languages: Language[]
timeLimit: number
memoryLimit: number
difficulty: Level
source: string
submissionCount: number
acceptedCount: number
acceptedRate: number
tags: Partial<Tag>[]
template: JsonValue[]
problemTestcase: Pick<ProblemTestcase, 'id' | 'input' | 'output'>[]
}

/**
* @deprecated _가 없는 것으로 사용해주세요
*/
@Exclude()
// eslint-disable-next-line
export class _ProblemResponseDto {
@Expose() id: number
@Expose() title: string
@Expose() description: string
Expand Down
35 changes: 30 additions & 5 deletions apps/backend/apps/client/src/problem/dto/problems.response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
import { Level, type Language, type Tag } from '@prisma/client'
import type { Language, Level, Tag } from '@prisma/client'
import { Exclude, Expose, Type } from 'class-transformer'

@Exclude()
export class ProblemsResponseDto {
@Expose()
@Type(() => Problem)
data: Problem[]
total: number
}

class Problem {
id: number
title: string
engTitle: string | null
difficulty: Level
submissionCount: number
acceptedRate: number
tags: Partial<Tag>[]
languages: Language[]
hasPassed: boolean | null
}

/**
* @deprecated _가 없는 것으로 사용해주세요
*/
@Exclude()
// eslint-disable-next-line
export class _ProblemsResponseDto {
@Expose()
@Type(() => _Problem)
data: _Problem[]

@Expose()
total: number
}

/**
* @deprecated _가 없는 것으로 사용해주세요
*/
@Exclude()
class Problem {
// eslint-disable-next-line
class _Problem {
@Expose()
id: number

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import { Problem } from '@prisma/client'
import type { Problem } from '@prisma/client'
import { Exclude, Expose, Type } from 'class-transformer'
import { ProblemResponseDto } from './problem.response.dto'
import {
_ProblemResponseDto,
type ProblemResponseDto
} from './problem.response.dto'

@Exclude()
export class RelatedProblemResponseDto {
order: number
problem: ProblemResponseDto
}

/**
* @deprecated _가 없는 것으로 사용해주세요
*/
@Exclude()
// eslint-disable-next-line
export class _RelatedProblemResponseDto {
@Expose()
order: number

@Expose()
@Type(() => ProblemResponseDto)
@Type(() => _ProblemResponseDto)
problem: Problem
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
import { Level } from '@prisma/client'
import type { Level } from '@prisma/client'
import { Exclude, Expose, Transform, Type } from 'class-transformer'
import { IsOptional } from 'class-validator'

@Exclude()
export class RelatedProblemsResponseDto {
@Expose()
@Type(() => Problem)
data: Problem[]
total: number
}

class Problem {
order: number
id: number
title: string
difficulty: Level
submissionCount: number
acceptedRate: number
maxScore: number | null
score: string | null
submissionTime: Date | null
}

/**
* @deprecated _가 없는 것으로 사용해주세요
*/
@Exclude()
// eslint-disable-next-line
export class _RelatedProblemsResponseDto {
@Expose()
@Type(() => _Problem)
data: _Problem[]

@Expose()
total: number
}

/**
* @deprecated _가 없는 것으로 사용해주세요
*/
@Exclude()
class Problem {
// eslint-disable-next-line
class _Problem {
@Expose()
order: number

Expand Down
14 changes: 6 additions & 8 deletions apps/backend/apps/client/src/problem/mock/problem.mock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { faker } from '@faker-js/faker'
import { Language, Level, Role } from '@prisma/client'
import type {
Problem,
Contest,
ContestProblem,
WorkbookProblem
} from '@prisma/client'
import type { Contest, ContestProblem, WorkbookProblem } from '@prisma/client'
import { MIN_DATE } from '@libs/constants'
import type { Problem } from '@admin/@generated'
import type { CreateTemplateDto } from '../dto/create-code-draft.dto'

export const problems: Problem[] = [
Expand Down Expand Up @@ -35,7 +31,8 @@ export const problems: Problem[] = [
engDescription: null,
engHint: null,
engInputDescription: null,
engOutputDescription: null
engOutputDescription: null,
problemTestcase: []
},
{
id: 2,
Expand All @@ -62,7 +59,8 @@ export const problems: Problem[] = [
engDescription: null,
engHint: null,
engInputDescription: null,
engOutputDescription: null
engOutputDescription: null,
problemTestcase: []
}
]

Expand Down
5 changes: 1 addition & 4 deletions apps/backend/apps/client/src/problem/problem.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ContestProblemController,
ProblemController
} from './problem.controller'
import { ProblemRepository } from './problem.repository'
import {
ContestProblemService,
ProblemService,
Expand All @@ -28,9 +27,7 @@ import {
ContestProblemService,
WorkbookProblemService,
CodeDraftService,
ProblemRepository,
{ provide: APP_GUARD, useClass: GroupMemberGuard }
],
exports: [ProblemRepository]
]
})
export class ProblemModule {}
Loading
Loading