Skip to content

Commit

Permalink
성주님의 피드백 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
vimkim committed Dec 7, 2023
1 parent da56c82 commit fe2d72f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 42 deletions.
9 changes: 4 additions & 5 deletions server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ export class AppController {

if (user && isUserSession(user)) {
const userSession: UserSession = { ...(req.user as User) } as UserSession;
const room = await this.roomService.findRoomParticipating(user);
this.logger.debug(
`The current user is participating in room: ${room?.code}`,
);
userSession.participatingRoomCode = room?.code;
const joinedRooms = await this.roomService.findJoinedRooms(user);
if (joinedRooms.length > 0) {
userSession.participatingRoomCode = joinedRooms[0].room?.code;
}
return userSession;
}

Expand Down
14 changes: 0 additions & 14 deletions server/src/room/room.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Logger,
Param,
Post,
Req,
UseGuards,
Expand Down Expand Up @@ -40,18 +38,6 @@ export class RoomController {
return { code: room.code };
}

@Get('/:code')
async roomInfo(@Param('code') code: string) {
const users = (await this.roomService.getRoomUsers(code)).map(
(roomUser) => {
return roomUser.user?.username;
},
);
return {
users,
};
}

@Post('join')
@HttpCode(HttpStatus.OK)
async joinRoom(@Req() req: Request, @Body() body: { code: string }) {
Expand Down
30 changes: 7 additions & 23 deletions server/src/room/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class RoomService {
}

async joinRoom(user: User, roomCode: string) {
const joinedRooms = await user.joinedRooms;
const joinedRooms = this.findJoinedRooms(user);

if (joinedRooms != null) {
throw new BadRequestException('이미 참가한 방이 있습니다.');
Expand Down Expand Up @@ -104,30 +104,14 @@ export class RoomService {
}
}

async findRoomParticipating(user: User) {
const roomUser = await this.roomUserService.findRoomUserByUser(user);
if (!roomUser) {
this.logger.warn(
`user ${user.username} is not participating in any room!`,
async findJoinedRooms(user: User) {
const joinedRooms = await user.joinedRooms;
if (joinedRooms == null) {
throw new InternalServerErrorException(
'참가 중인 방을 찾을 수 없습니다.',
);
return null;
}
return this.roomRepository.findOne({
where: {
joinedUsers: { id: roomUser.id },
},
});
}

async getRoomInfo(code: string) {
return this.roomUserRepository.count({
where: { room: { code } },
});
}

async getRoomUsers(code: string) {
return this.roomUserRepository.find({
where: { room: { code } },
});
return joinedRooms;
}
}

0 comments on commit fe2d72f

Please sign in to comment.