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

[REFACTOR] ChatException throw 시, roomId 를 담아서 throw 하도록 수정 #261

Merged
merged 1 commit into from
Dec 2, 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
2 changes: 1 addition & 1 deletion backend/chatServer/src/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
const banUser = this.server.sockets.sockets.get(socketId);
const address = banUser?.handshake.address.replaceAll('::ffff:', '');

if(!address) throw new ChatException(CHATTING_SOCKET_ERROR.INVALID_USER);
if(!address) throw new ChatException(CHATTING_SOCKET_ERROR.INVALID_USER, roomId);

const forwarded = banUser?.handshake.headers.forwarded ?? address;
console.log('ban:', roomId, address, forwarded);
Expand Down
6 changes: 3 additions & 3 deletions backend/chatServer/src/room/room.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class RoomRepository {

async getHost(roomId: string) {
const hostId = await this.redisClient.get(this.getRoomStringWithPrefix(roomId));
if(!hostId) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if(!hostId) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
return hostId;
}

Expand All @@ -98,7 +98,7 @@ export class RoomRepository {

async markQuestionAsDone(roomId: string, questionId: number): Promise<QuestionDto> {
const question = await this.getQuestion(roomId, questionId);
if(!question) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY);
if(!question) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId);
question.questionDone = true;
this.redisClient.lset(this.getQuestionStringWithPrefix(roomId), questionId, JSON.stringify(question));
return question;
Expand All @@ -114,7 +114,7 @@ export class RoomRepository {
async getQuestion(roomId: string, questionId: number): Promise<QuestionDto> {
const question = await this.lindex<Omit<QuestionDto, 'questionId'>>(this.getQuestionStringWithPrefix(roomId), questionId);
if(question) return {...question, questionId };
throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY);
throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId);
}

async getQuestionId(roomId: string) {
Expand Down
18 changes: 9 additions & 9 deletions backend/chatServer/src/room/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ export class RoomService implements OnModuleInit, OnModuleDestroy {
// 방 삭제
async deleteRoom(roomId: string) {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
await this.redisRepository.deleteRoom(roomId);
}

async addQuestion(roomId: string, question: Omit<QuestionDto, 'questionId'>){
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);

return await this.redisRepository.addQuestionToRoom(roomId, question);
}
Expand All @@ -102,40 +102,40 @@ export class RoomService implements OnModuleInit, OnModuleDestroy {
question: Omit<QuestionDto, 'questionId'>,
): Promise<QuestionDto> {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);

return await this.redisRepository.addQuestionToRoom(roomId, question);
}

// 특정 질문 완료 처리
async markQuestionAsDone(roomId: string, questionId: number) {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);

const markedQuestion = await this.redisRepository.markQuestionAsDone(roomId, questionId);
if (!markedQuestion) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY);
if (!markedQuestion) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId);
return markedQuestion;
}

// 방에 속한 모든 질문 조회
async getQuestions(roomId: string): Promise<QuestionDto[]> {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);

return this.redisRepository.getQuestionsAll(roomId);
}

async getQuestionsNotDone(roomId: string): Promise<QuestionDto[]> {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);

return this.redisRepository.getQuestionsUnmarked(roomId);
}

// 특정 질문 조회
async getQuestion(roomId: string, questionId: number): Promise<QuestionDto> {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
return this.redisRepository.getQuestion(roomId, questionId);
}

Expand Down Expand Up @@ -163,7 +163,7 @@ export class RoomService implements OnModuleInit, OnModuleDestroy {

async getHostOfRoom(roomId: string) {
const roomExists = await this.redisRepository.isRoomExisted(roomId);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
return await this.redisRepository.getHost(roomId);
}

Expand Down
Loading