From e86d9a5213b1386042babee417b03b38a4f32dd0 Mon Sep 17 00:00:00 2001 From: hysong4u Date: Thu, 18 Jan 2024 23:16:29 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EC=84=A0=EB=AC=BC=EB=B0=A9=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=EC=9E=90=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EB=A1=9C=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/room/controller/RoomController.java | 6 ++++++ .../room/dto/response/RoomMemberDetailDto.java | 6 +----- .../room/dto/response/RoomOwnerDetailDto.java | 16 ++++++++++++++++ .../sweet/domain/room/service/RoomService.java | 12 ++++++++---- 4 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/sopt/sweet/domain/room/dto/response/RoomOwnerDetailDto.java diff --git a/src/main/java/org/sopt/sweet/domain/room/controller/RoomController.java b/src/main/java/org/sopt/sweet/domain/room/controller/RoomController.java index 25fe1a3..dfb0404 100644 --- a/src/main/java/org/sopt/sweet/domain/room/controller/RoomController.java +++ b/src/main/java/org/sopt/sweet/domain/room/controller/RoomController.java @@ -67,6 +67,12 @@ public ResponseEntity> getRoomMembers(@UserId Long userId, @P return SuccessResponse.ok(roomMemberDetailDto); } + @GetMapping("/{roomId}/room-detail") + public ResponseEntity> getRoom(@UserId Long userId, @PathVariable Long roomId) { + final RoomOwnerDetailDto roomOwnerDetailDto = roomService.getRoom(userId, roomId); + return SuccessResponse.ok(roomOwnerDetailDto); + } + @DeleteMapping("/{roomId}/members/{memberId}") public ResponseEntity> deleteRoomMember(@UserId Long userId, @PathVariable Long roomId, @PathVariable Long memberId) { roomService.deleteRoomMember(userId, roomId, memberId); diff --git a/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomMemberDetailDto.java b/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomMemberDetailDto.java index 3ba5973..cd43e46 100644 --- a/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomMemberDetailDto.java +++ b/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomMemberDetailDto.java @@ -6,14 +6,10 @@ @Builder public record RoomMemberDetailDto( - RoomDto room, - OwnerDto owner, List members ) { - public static RoomMemberDetailDto of(RoomDto roomDto, OwnerDto ownerDto, List roomMemberDtoList) { + public static RoomMemberDetailDto of(List roomMemberDtoList) { return RoomMemberDetailDto.builder() - .room(roomDto) - .owner(ownerDto) .members(roomMemberDtoList) .build(); } diff --git a/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomOwnerDetailDto.java b/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomOwnerDetailDto.java new file mode 100644 index 0000000..da7d89f --- /dev/null +++ b/src/main/java/org/sopt/sweet/domain/room/dto/response/RoomOwnerDetailDto.java @@ -0,0 +1,16 @@ +package org.sopt.sweet.domain.room.dto.response; + +import lombok.Builder; + +@Builder +public record RoomOwnerDetailDto( + RoomDto room, + OwnerDto owner +) { + public static RoomOwnerDetailDto of(RoomDto roomDto, OwnerDto ownerDto) { + return RoomOwnerDetailDto.builder() + .room(roomDto) + .owner(ownerDto) + .build(); + } +} diff --git a/src/main/java/org/sopt/sweet/domain/room/service/RoomService.java b/src/main/java/org/sopt/sweet/domain/room/service/RoomService.java index 36f2f06..05eaf15 100644 --- a/src/main/java/org/sopt/sweet/domain/room/service/RoomService.java +++ b/src/main/java/org/sopt/sweet/domain/room/service/RoomService.java @@ -1,7 +1,6 @@ package org.sopt.sweet.domain.room.service; import lombok.RequiredArgsConstructor; -import org.hibernate.internal.util.collections.StandardStack; import org.sopt.sweet.domain.gift.entity.Gift; import org.sopt.sweet.domain.gift.repository.GiftRepository; import org.sopt.sweet.domain.member.entity.Member; @@ -149,14 +148,19 @@ public void modifyRoomGifteeName(Long memberId, Long roomId, RoomNameRequestDto @Transactional(readOnly = true) public RoomMemberDetailDto getRoomMembers(Long memberId, Long roomId) { + List roomMembers = roomMemberRepository.findByRoomId(roomId); + List roomMemberDtoList = mapToRoomMemberDtoList(roomMembers); + return RoomMemberDetailDto.of(roomMemberDtoList); + } + + @Transactional(readOnly = true) + public RoomOwnerDetailDto getRoom(Long memberId, Long roomId) { Member member = findMemberByIdOrThrow(memberId); Room room = findByIdOrThrow(roomId); checkRoomHost(member, room); - List roomMembers = roomMemberRepository.findByRoomId(roomId); - List roomMemberDtoList = mapToRoomMemberDtoList(roomMembers); RoomDto roomDto = new RoomDto(room.getGifteeName(), room.getGifterNumber()); OwnerDto ownerDto = new OwnerDto(room.getHost().getId(), room.getHost().getProfileImg(), room.getHost().getNickName()); - return RoomMemberDetailDto.of(roomDto, ownerDto, roomMemberDtoList); + return RoomOwnerDetailDto.of(roomDto, ownerDto); } public void deleteRoomMember(Long memberId, Long roomId, Long deleteMemberId) {