Skip to content

Commit

Permalink
Merge pull request #261 from boostcampwm-2024/feature-be-#250-ban_user
Browse files Browse the repository at this point in the history
[Refactor] ChatException throw 시, roomId 를 담아서 throw 하도록 수정
  • Loading branch information
hoeeeeeh authored Dec 2, 2024
2 parents cce1a34 + 8175734 commit 6a45640
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
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

0 comments on commit 6a45640

Please sign in to comment.