Skip to content

Commit

Permalink
Merge pull request #282 from DongHoonYu96/feature-be-#281
Browse files Browse the repository at this point in the history
[BE] feat#281 카테고리 enum 설정
  • Loading branch information
DongHoonYu96 authored Nov 28, 2024
2 parents 5b9e261 + d5a9f94 commit 6b83551
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
25 changes: 24 additions & 1 deletion BE/src/quiz-set/entities/quiz-set.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ import { UserModel } from '../../user/entities/user.entity';
import { QuizModel } from './quiz.entity';
import { UserQuizArchiveModel } from '../../user/entities/user-quiz-archive.entity';

const CategoriesEnum = Object.freeze({
GENERAL: 'GENERAL',
MOVIE: 'MOVIE',
MUSIC: 'MUSIC',
FOOD: 'FOOD',
ANIMAL: 'ANIMAL',
LANGUAGE: 'LANGUAGE',
NEWS: 'NEWS',
MATH: 'MATH',
SCIENCE: 'SCIENCE',
ECONOMY: 'ECONOMY',
HISTORY: 'HISTORY',
GEOGRAPHY: 'GEOGRAPHY',
SPORTS: 'SPORTS',
GAME: 'GAME',
IT: 'IT',
POLITICS: 'POLITICS'
});

@Entity('quiz_set')
export class QuizSetModel extends BaseModel {
@Column()
Expand All @@ -12,7 +31,11 @@ export class QuizSetModel extends BaseModel {
@Column({ name: 'user_id' })
userId: number;

@Column()
@Column({
type: 'enum',
enum: CategoriesEnum,
default: CategoriesEnum.GENERAL // 기본값 설정 가능
})
category: string;

@ManyToOne(() => UserModel, (user) => user.quizSetList, {
Expand Down
11 changes: 8 additions & 3 deletions BE/src/quiz-set/quiz-set.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
DefaultValuePipe,
Delete,
Get,
Logger,
Param,
Patch,
Post,
Query,
UseGuards,
Logger
UseGuards
} from '@nestjs/common';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import { QuizSetService } from './service/quiz-set.service';
Expand Down Expand Up @@ -44,7 +44,12 @@ export class QuizSetController {
@Query('take', new ParseIntOrDefault(10)) take: number,
@Query('search', new DefaultValuePipe('')) search: string
) {
const result = await this.quizService.findAllWithQuizzesAndChoices(category, cursor, take, search);
const result = await this.quizService.findAllWithQuizzesAndChoices(
category,
cursor,
take,
search
);
this.logger.verbose(`퀴즈셋 목록 조회: ${result}`);
return result;
}
Expand Down
10 changes: 10 additions & 0 deletions BE/src/quiz-set/service/quiz-set-create.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ export class QuizSetCreateService {
}

private handleError(error: Error): never {
const mysqlError = error as unknown as {
code: number;
errno: number;
sqlState: string;
sqlMessage: string;
};
if (mysqlError.errno === 1265) {
throw new BadRequestException('퀴즈셋 생성 실패: 올바른 카테고리를 입력해주세요');
}

if (error instanceof BadRequestException) {
throw error;
}
Expand Down

0 comments on commit 6b83551

Please sign in to comment.