Skip to content

Commit

Permalink
Merge pull request #3 from boostcampwm-2024/feature/BE-redis
Browse files Browse the repository at this point in the history
베팅방 요약 조회 API 구현
  • Loading branch information
dngyj authored Jan 21, 2025
2 parents f6c7ac7 + ca58eef commit 6add973
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
32 changes: 31 additions & 1 deletion backend/src/bet-room/bet-room.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,41 @@ export class BetRoomController {
}

@UseGuards(JwtGuestAuthGuard)
@Get("/:betRoomId")
@Get("/:betRoomId/summary")
async getBetRoom(
@Param("betRoomId") betRoomId: string,
@Req() req: Request,
@Res() res: Response,
) {
try {
const userId = req["user"].id;
const betRoomData = await this.betRoomService.findBetRoomSummaryById(
userId,
betRoomId,
);
return res.status(HttpStatus.OK).json({
status: HttpStatus.OK,
data: {
channel: betRoomData,
message: "OK",
},
});
} catch (error) {
return res.status(error.status || HttpStatus.INTERNAL_SERVER_ERROR).json({
status: error.status || HttpStatus.INTERNAL_SERVER_ERROR,
data: {
message: error.message || "Internal Server Error",
},
});
}
}

@UseGuards(JwtGuestAuthGuard)
@Get("/:betRoomId")
async getBetRoomDetails(
@Param("betRoomId") betRoomId: string,
@Req() req: Request,
@Res() res: Response,
) {
try {
const userId = req["user"].id;
Expand Down
25 changes: 25 additions & 0 deletions backend/src/bet-room/bet-room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,31 @@ export class BetRoomService {
return updateResult;
}

async findBetRoomSummaryById(userId: number | string, betRoomId: string) {
const betRoom = await this.betRoomRepository.findOneById(betRoomId);
if (!betRoom) {
throw new NotFoundException(
`해당하는 베팅방이 존재하지 않습니다. Id: ${betRoomId}`,
);
}
return {
title: betRoom.title,
options: {
option1: {
name: betRoom.option1,
},
option2: {
name: betRoom.option2,
},
},
status: betRoom.status,
settings: {
defaultBetAmount: betRoom.defaultBetAmount,
duration: betRoom.timer,
},
};
}

async findBetRoomById(userId: number | string, betRoomId: string) {
const betRoom = await this.betRoomRepository.findOneById(betRoomId);
if (!betRoom) {
Expand Down

0 comments on commit 6add973

Please sign in to comment.