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

[BE] feat#281 카테고리 enum 설정 #282

Merged
merged 3 commits into from
Nov 28, 2024
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
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