Skip to content

Commit

Permalink
Merge pull request #95 from SWEET-DEVELOPERS/feature/#94-room
Browse files Browse the repository at this point in the history
[fix] 선물방 참여자 상세 조회 API 로직 분리
  • Loading branch information
hysong4u authored Jan 18, 2024
2 parents fd7b5b2 + e86d9a5 commit 537c51c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public ResponseEntity<SuccessResponse<?>> getRoomMembers(@UserId Long userId, @P
return SuccessResponse.ok(roomMemberDetailDto);
}

@GetMapping("/{roomId}/room-detail")
public ResponseEntity<SuccessResponse<?>> getRoom(@UserId Long userId, @PathVariable Long roomId) {
final RoomOwnerDetailDto roomOwnerDetailDto = roomService.getRoom(userId, roomId);
return SuccessResponse.ok(roomOwnerDetailDto);
}

@DeleteMapping("/{roomId}/members/{memberId}")
public ResponseEntity<SuccessResponse<?>> deleteRoomMember(@UserId Long userId, @PathVariable Long roomId, @PathVariable Long memberId) {
roomService.deleteRoomMember(userId, roomId, memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@

@Builder
public record RoomMemberDetailDto(
RoomDto room,
OwnerDto owner,
List<RoomMemberDto> members
) {
public static RoomMemberDetailDto of(RoomDto roomDto, OwnerDto ownerDto, List<RoomMemberDto> roomMemberDtoList) {
public static RoomMemberDetailDto of(List<RoomMemberDto> roomMemberDtoList) {
return RoomMemberDetailDto.builder()
.room(roomDto)
.owner(ownerDto)
.members(roomMemberDtoList)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,19 @@ public void modifyRoomGifteeName(Long memberId, Long roomId, RoomNameRequestDto

@Transactional(readOnly = true)
public RoomMemberDetailDto getRoomMembers(Long memberId, Long roomId) {
List<RoomMember> roomMembers = roomMemberRepository.findByRoomId(roomId);
List<RoomMemberDto> 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<RoomMember> roomMembers = roomMemberRepository.findByRoomId(roomId);
List<RoomMemberDto> 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) {
Expand Down

0 comments on commit 537c51c

Please sign in to comment.