Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 선물방 참여자 상세 조회 API 로직 분리 #95

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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
@@ -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;
Expand Down Expand Up @@ -149,14 +148,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