From 9b8b57e27738d888df453b3d535609aaf856c908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=84=ED=98=84=EB=AF=BC?= <77275989+joyjhm@users.noreply.github.com> Date: Sun, 19 Jan 2025 19:30:06 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B3=B5=EC=9C=A0=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/quiz-zone/src/constant.ts | 104 ------------------ .../src/entities/quiz-zone.entity.ts | 30 ----- apps/quiz-zone/src/entities/quiz.entity.ts | 13 --- apps/quiz-zone/src/entities/rank.entity.ts | 6 - .../src/entities/submitted-quiz.entity.ts | 15 --- .../src/quiz-zone/chat-message.interface.ts | 5 - .../src/quiz-zone/dto/create-quiz-zone.dto.ts | 16 --- .../src/quiz-zone/dto/current-quiz.dto.ts | 20 ---- .../src/quiz-zone/dto/find-quiz-zone.dto.ts | 53 --------- .../dto/find-quizzes-response.dto.ts | 9 -- .../src/quiz-zone/quiz-zone.controller.ts | 6 +- .../quiz-zone/quiz-zone.redis.repository.ts | 2 +- .../quiz-zone.repository.interface.ts | 2 +- .../src/quiz-zone/quiz-zone.service.ts | 39 ++++--- packages/shared/src/constants.ts | 5 + 15 files changed, 28 insertions(+), 297 deletions(-) delete mode 100644 apps/quiz-zone/src/constant.ts delete mode 100644 apps/quiz-zone/src/entities/quiz-zone.entity.ts delete mode 100644 apps/quiz-zone/src/entities/quiz.entity.ts delete mode 100644 apps/quiz-zone/src/entities/rank.entity.ts delete mode 100644 apps/quiz-zone/src/entities/submitted-quiz.entity.ts delete mode 100644 apps/quiz-zone/src/quiz-zone/chat-message.interface.ts delete mode 100644 apps/quiz-zone/src/quiz-zone/dto/create-quiz-zone.dto.ts delete mode 100644 apps/quiz-zone/src/quiz-zone/dto/current-quiz.dto.ts delete mode 100644 apps/quiz-zone/src/quiz-zone/dto/find-quiz-zone.dto.ts delete mode 100644 apps/quiz-zone/src/quiz-zone/dto/find-quizzes-response.dto.ts diff --git a/apps/quiz-zone/src/constant.ts b/apps/quiz-zone/src/constant.ts deleted file mode 100644 index 755ff25..0000000 --- a/apps/quiz-zone/src/constant.ts +++ /dev/null @@ -1,104 +0,0 @@ -export enum QUIZ_ZONE_STAGE { - LOBBY = 'LOBBY', - IN_PROGRESS = 'IN_PROGRESS', - RESULT = 'RESULT', -} - -export enum PLAYER_STATE { - WAIT = 'WAIT', - PLAY = 'PLAY', - SUBMIT = 'SUBMIT', -} - -export const CLOSE_CODE = { - NORMAL: 1000, - GOING_AWAY: 1001, - PROTOCOL_ERROR: 1002, - REFUSE: 1003, - NO_STATUS: 1005, - ABNORMAL: 1006, - INCONSISTENT_DATA: 1007, - POLICY_VIOLATION: 1008, -}; - -// 닉네임 접두사 -export const prefixes: string[] = [ - '불사조', - '천상의', - '불의', - '붉은', - '어둠의', - '달빛', - '푸른', - '검은', - '황금의', - '은빛', - '새벽의', - '태양의', - '영원의', - '바다의', - '대지의', - '하늘의', - '강철의', - '빛의', - '고대의', - '심연의', - '구름의', - '섬광의', - '운명의', - '폭풍의', - '신비의', - '얼음의', - '화염의', - '별의', - '천둥의', - '미친', -]; - -// 닉네임 접미사 -export const suffixes: string[] = [ - '마법사', - '현자', - '검사', - '용사', - '기사', - '전사', - '궁수', - '암살자', - '무사', - '도적', - '영웅', - '제왕', - '성자', - '마왕', - '기병', - '법사', - '검객', - '마술사', - '투사', - '마수', - '검투사', - '마인', - '왕', - '사제', - '괴수', - '현자', - '용자', - '유령', - '악마', - '정령', -]; - -export const getRandomNickName = (): string => { - return `${prefixes[Math.floor(Math.random() * prefixes.length)]}${suffixes[Math.floor(Math.random() * suffixes.length)]}`; -}; - -export enum QUIZ_TYPE { - SHORT_ANSWER = 'SHORT', -} - -export const INTERVAL_TIME = 5000; - -export const QUIZ_SERVER_URL = 'http://quiz-service:3001'; -export const CHAT_SERVER_URL = 'http://chat-server:3002'; - diff --git a/apps/quiz-zone/src/entities/quiz-zone.entity.ts b/apps/quiz-zone/src/entities/quiz-zone.entity.ts deleted file mode 100644 index f9727dc..0000000 --- a/apps/quiz-zone/src/entities/quiz-zone.entity.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Quiz } from './quiz.entity'; -/** - * 퀴즈 게임을 진행하는 공간을 나타내는 퀴즈존 인터페이스 - * - * @property players 플레이어 목록 - * @property hostId 퀴즈 존을 생성한 관리자 ID - * @property maxPlayers 퀴즈 존의 최대 플레이어 수 - * @property quizzes 퀴즈 목록 - * @property stage 퀴즈 존의 현재 상태 - * @property title 퀴즈 세트의 제목 - * @property description 퀴즈 세트의 설명 - * @property currentQuizIndex 현재 출제 중인 퀴즈의 인덱스 - * @property currentQuizStartTime 현재 퀴즈의 출제 시작 시간 - * @property currentQuizDeadlineTime 현재 퀴즈의 제출 마감 시간 - * @property intervalTime 퀴즈 간의 간격 시간 - */ -export interface QuizZone { - players: Map; // Player - hostId: string; - maxPlayers: number; - quizzes: Quiz[]; - stage: any; // QUIZ_ZONE_STAGE - title: string; - description: string; - currentQuizIndex: number; - currentQuizStartTime: number; - currentQuizDeadlineTime: number; - intervalTime: number; - summaries?: any; // QuizSummary -} diff --git a/apps/quiz-zone/src/entities/quiz.entity.ts b/apps/quiz-zone/src/entities/quiz.entity.ts deleted file mode 100644 index b0faad0..0000000 --- a/apps/quiz-zone/src/entities/quiz.entity.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * 퀴즈 엔티티 - * - * @property question: 퀴즈의 질문 - * @property answer: 퀴즈의 정답 - * @property playTime: 퀴즈의 플레이 시간 - */ -export interface Quiz { - question: string; - answer: string; - playTime: number; - quizType: any; // QUIZ_TYPE -} diff --git a/apps/quiz-zone/src/entities/rank.entity.ts b/apps/quiz-zone/src/entities/rank.entity.ts deleted file mode 100644 index 7854840..0000000 --- a/apps/quiz-zone/src/entities/rank.entity.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Rank { - readonly id: string; - readonly nickname: string; - readonly score: number; - readonly ranking: number; -} \ No newline at end of file diff --git a/apps/quiz-zone/src/entities/submitted-quiz.entity.ts b/apps/quiz-zone/src/entities/submitted-quiz.entity.ts deleted file mode 100644 index 1b81796..0000000 --- a/apps/quiz-zone/src/entities/submitted-quiz.entity.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * 플레이어가 제출한 퀴즈 엔티티 - * - * @property index: 퀴즈의 인덱스 - * @property answer: 플레이어가 제출한 답 - * @property submittedAt: 플레이어가 제출한 시각 - * @property receivedAt: 플레이어가 제출한 시각 - */ -export interface SubmittedQuiz { - index: number; - answer?: string; - submittedAt?: number; - receivedAt?: number; - submitRank?: number; -} diff --git a/apps/quiz-zone/src/quiz-zone/chat-message.interface.ts b/apps/quiz-zone/src/quiz-zone/chat-message.interface.ts deleted file mode 100644 index 3bdc201..0000000 --- a/apps/quiz-zone/src/quiz-zone/chat-message.interface.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface ChatMessage { - clientId: string; - nickname: string; - message: string; -} \ No newline at end of file diff --git a/apps/quiz-zone/src/quiz-zone/dto/create-quiz-zone.dto.ts b/apps/quiz-zone/src/quiz-zone/dto/create-quiz-zone.dto.ts deleted file mode 100644 index 82f3647..0000000 --- a/apps/quiz-zone/src/quiz-zone/dto/create-quiz-zone.dto.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * 퀴즈존을 생성할 때 사용하는 DTO 클래스 - * - * 퀴즈존 ID는 다음 규칙을 따릅니다: - * - 5-10글자 길이 - * - 숫자와 알파벳 조합 - * - 중복 불가 (중복 체크 로직 추가 예정) - */ - -export class CreateQuizZoneDto { - readonly quizZoneId: string; - readonly title: string; - readonly description: string; - readonly limitPlayerCount: number; - readonly quizSetId: number; -} diff --git a/apps/quiz-zone/src/quiz-zone/dto/current-quiz.dto.ts b/apps/quiz-zone/src/quiz-zone/dto/current-quiz.dto.ts deleted file mode 100644 index 94d621b..0000000 --- a/apps/quiz-zone/src/quiz-zone/dto/current-quiz.dto.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { QUIZ_ZONE_STAGE } from '../../constant'; - -/** - * 현재 진행중인 퀴즈에 대한 DTO - * - * @property question - 현재 진행 중인 퀴즈의 질문 - * @property stage - 현재 퀴즈의 진행 상태 - * @property currentIndex - 현재 퀴즈의 인덱스 - * @property playTime - 퀴즈 플레이 시간 - * @property startTime - 퀴즈 시작 시간 - * @property deadlineTime - 퀴즈 마감 시간 - */ -export interface CurrentQuizDto { - readonly question: string; - readonly stage: QUIZ_ZONE_STAGE; - readonly currentIndex: number; - readonly playTime: number; - readonly startTime: number; - readonly deadlineTime: number; -} diff --git a/apps/quiz-zone/src/quiz-zone/dto/find-quiz-zone.dto.ts b/apps/quiz-zone/src/quiz-zone/dto/find-quiz-zone.dto.ts deleted file mode 100644 index 6cb5143..0000000 --- a/apps/quiz-zone/src/quiz-zone/dto/find-quiz-zone.dto.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { ChatMessage } from '../chat-message.interface'; -import { PLAYER_STATE, QUIZ_ZONE_STAGE } from '../../constant'; -import { SubmittedQuiz } from '../../entities/submitted-quiz.entity'; -import { Quiz } from '../../entities/quiz.entity'; -import { CurrentQuizDto } from './current-quiz.dto'; -import { Rank } from '../../entities/rank.entity'; - -/** - * 퀴즈 게임에 참여하는 플레이어 엔티티 - * - * @property id: 플레이어 세션 ID - * @property nickname: 플레이어의 닉네임 - * @property score: 플레이어의 점수 - * @property submits: 플레이어가 제출한 퀴즈 목록 - * @property state: 플레이어의 현재 상태 - */ -export interface Player { - id: string; - nickname: string; - score?: number; - submits?: SubmittedQuiz[]; - state: PLAYER_STATE; -} - -/** - * 퀴즈 존을 찾기 위한 DTO - * - * @property currentPlayer - 현재 플레이어 - * @property title - 퀴즈 존의 제목 - * @property description - 퀴즈 존의 설명 - * @property quizCount - 퀴즈 존의 퀴즈 개수 - * @property stage - 퀴즈 존의 진행 상태 - * @property hostId - 퀴즈 존의 호스트 ID - * @property currentQuiz - 현재 출제 중인 퀴즈 - * @property maxPlayers - 퀴즈 존의 최대 플레이어 수 - */ -export interface FindQuizZoneDto { - readonly currentPlayer: Player; - readonly title: string; - readonly description: string; - readonly quizCount: number; - readonly stage: QUIZ_ZONE_STAGE; - readonly hostId: string; - readonly currentQuiz?: CurrentQuizDto; - readonly maxPlayers?: number; - readonly chatMessages?: ChatMessage[]; - - readonly ranks?: Rank[]; - readonly endSocketTime?: number; - readonly score?: number; - readonly quizzes?: Quiz[]; - readonly submits?: SubmittedQuiz[]; -} diff --git a/apps/quiz-zone/src/quiz-zone/dto/find-quizzes-response.dto.ts b/apps/quiz-zone/src/quiz-zone/dto/find-quizzes-response.dto.ts deleted file mode 100644 index 134c01e..0000000 --- a/apps/quiz-zone/src/quiz-zone/dto/find-quizzes-response.dto.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { QUIZ_TYPE } from '../../constant'; - -export class FindQuizzesResponseDto { - readonly question: string; - readonly answer: string; - readonly playTime: number; - readonly quizType: QUIZ_TYPE; - readonly id: number; -} diff --git a/apps/quiz-zone/src/quiz-zone/quiz-zone.controller.ts b/apps/quiz-zone/src/quiz-zone/quiz-zone.controller.ts index c2be86b..a42438c 100644 --- a/apps/quiz-zone/src/quiz-zone/quiz-zone.controller.ts +++ b/apps/quiz-zone/src/quiz-zone/quiz-zone.controller.ts @@ -10,10 +10,8 @@ import { } from '@nestjs/common'; import { QuizZoneService } from './quiz-zone.service'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { CreateQuizZoneDto } from './dto/create-quiz-zone.dto' -import { QuizZone } from '../entities/quiz-zone.entity'; -import { CHAT_SERVER_URL } from '../constant'; import { CustomHttpService } from '../http/http.service'; +import { CHAT_SERVER_URL, QuizZone, RequestCreateQuizZone } from '@web08-booquiz/shared'; @ApiTags('Quiz Zone') @@ -30,7 +28,7 @@ export class QuizZoneController { @ApiResponse({ status: 201, description: '퀴즈존이 성공적으로 생성되었습니다.' }) @ApiResponse({ status: 400, description: '세션 정보가 없습니다.' }) async create( - @Body() createQuizZoneDto: CreateQuizZoneDto, + @Body() createQuizZoneDto: RequestCreateQuizZone, @Session() session: Record, ): Promise { if (!session || !session.id) { diff --git a/apps/quiz-zone/src/quiz-zone/quiz-zone.redis.repository.ts b/apps/quiz-zone/src/quiz-zone/quiz-zone.redis.repository.ts index b91bec7..06258f2 100644 --- a/apps/quiz-zone/src/quiz-zone/quiz-zone.redis.repository.ts +++ b/apps/quiz-zone/src/quiz-zone/quiz-zone.redis.repository.ts @@ -1,6 +1,6 @@ import { IQuizZoneRepository } from './quiz-zone.repository.interface'; import { RedisService } from '../redis/redis.service'; -import { QuizZone } from 'src/entities/quiz-zone.entity'; +import { QuizZone } from '@web08-booquiz/shared'; export class QuizZoneRedisRepository implements IQuizZoneRepository { constructor(private readonly redisService: RedisService) {} diff --git a/apps/quiz-zone/src/quiz-zone/quiz-zone.repository.interface.ts b/apps/quiz-zone/src/quiz-zone/quiz-zone.repository.interface.ts index 4e7c044..fd9cbd7 100644 --- a/apps/quiz-zone/src/quiz-zone/quiz-zone.repository.interface.ts +++ b/apps/quiz-zone/src/quiz-zone/quiz-zone.repository.interface.ts @@ -1,4 +1,4 @@ -import { QuizZone } from '../entities/quiz-zone.entity'; +import { QuizZone } from '@web08-booquiz/shared'; /** * 퀴즈 존 저장소를 위한 인터페이스입니다. diff --git a/apps/quiz-zone/src/quiz-zone/quiz-zone.service.ts b/apps/quiz-zone/src/quiz-zone/quiz-zone.service.ts index b45c442..d517c34 100644 --- a/apps/quiz-zone/src/quiz-zone/quiz-zone.service.ts +++ b/apps/quiz-zone/src/quiz-zone/quiz-zone.service.ts @@ -1,20 +1,18 @@ import { BadRequestException, ConflictException, Inject, Injectable, NotFoundException } from '@nestjs/common'; import { IQuizZoneRepository } from './quiz-zone.repository.interface'; -import { QuizZone } from '../entities/quiz-zone.entity'; -import { Quiz } from '../entities/quiz.entity'; -import { FindQuizzesResponseDto } from './dto/find-quizzes-response.dto' -import { FindQuizZoneDto, Player } from './dto/find-quiz-zone.dto'; -import { CreateQuizZoneDto } from './dto/create-quiz-zone.dto' -import { ChatMessage } from './chat-message.interface'; +import { CustomHttpService } from '../http/http.service'; import { CHAT_SERVER_URL, - getRandomNickName, - INTERVAL_TIME, + ChatMessage, FindQuizzesResponse, + getRandomNickName, INTERVAL_TIME, + Player, PLAYER_STATE, - QUIZ_SERVER_URL, + Quiz, QUIZ_SERVER_URL, QUIZ_ZONE_STAGE, -} from '../constant'; -import { CustomHttpService } from '../http/http.service'; + QuizZone, + RequestCreateQuizZone, + ResponseFindQuizZone, +} from '@web08-booquiz/shared'; @Injectable() export class QuizZoneService { @@ -34,7 +32,7 @@ export class QuizZoneService { * @returns 퀴즈 존을 생성하고 저장하는 비동기 작업 * @throws(ConflictException) 이미 저장된 ID인 경우 예외 발생 */ - async create(createQuizZoneDto: CreateQuizZoneDto, hostId: string): Promise { + async create(createQuizZoneDto: RequestCreateQuizZone, hostId: string): Promise { const { quizZoneId, title, description, limitPlayerCount, quizSetId } = createQuizZoneDto; const hasQuizZone = await this.repository.has(quizZoneId); @@ -50,9 +48,10 @@ export class QuizZoneService { state: PLAYER_STATE.WAIT, }; - const quizSet = await this.httpService.get(`${QUIZ_SERVER_URL}/quizSetId`) as FindQuizzesResponseDto[]; + const quizSet = await this.httpService.get(`${QUIZ_SERVER_URL}/quizSetId`) as FindQuizzesResponse[]; const quizzes: Quiz[] = quizSet.map((quiz) => ({ + id: quiz.id, question: Buffer.from(quiz.question).toString('base64'), answer: quiz.answer, playTime: quiz.playTime * 1000, @@ -117,14 +116,14 @@ export class QuizZoneService { return quizZone; } - private async getLobbyInfo(clinetId: string, quizZoneId: string): Promise { + private async getLobbyInfo(clinetId: string, quizZoneId: string): Promise { const { players, title, description, quizzes, stage, hostId, maxPlayers } = await this.findOne(quizZoneId); - const { id, nickname, state } = players.get(clinetId); + const player = players.get(clinetId); const chatMessages = await this.httpService.get(`${CHAT_SERVER_URL}/${quizZoneId}`) as ChatMessage[]; return { - currentPlayer: { id, nickname, state }, + currentPlayer: player, title: title, description: description, quizCount: quizzes.length, @@ -135,7 +134,7 @@ export class QuizZoneService { }; } - private async getProgressInfo(clientId: string, quizZoneId: string): Promise { + private async getProgressInfo(clientId: string, quizZoneId: string): Promise { const { players, stage, @@ -148,11 +147,11 @@ export class QuizZoneService { description, quizzes, } = await this.findOne(quizZoneId); - const { id, nickname, state } = players.get(clientId); + const player = players.get(clientId); const chatMessages = await this.httpService.get(`${CHAT_SERVER_URL}/${quizZoneId}`) as ChatMessage[]; return { - currentPlayer: { id, nickname, state }, + currentPlayer: player, title, description, quizCount: quizzes.length, @@ -171,7 +170,7 @@ export class QuizZoneService { }; } - private async getResultInfo(clientId: string, quizZoneId: string): Promise { + private async getResultInfo(clientId: string, quizZoneId: string): Promise { const { players, stage, title, description, hostId, quizzes, summaries } = await this.findOne(quizZoneId); const { id, nickname, state, submits, score } = players.get(clientId); diff --git a/packages/shared/src/constants.ts b/packages/shared/src/constants.ts index 5e69e13..cdc8675 100644 --- a/packages/shared/src/constants.ts +++ b/packages/shared/src/constants.ts @@ -96,3 +96,8 @@ export const getRandomNickName = (): string => { export enum QUIZ_TYPE { SHORT_ANSWER = 'SHORT', } + +export const INTERVAL_TIME = 5000; + +export const QUIZ_SERVER_URL = 'http//quiz-server:3001' +export const CHAT_SERVER_URL = 'http//chat-server:3002'