diff --git a/src/main/java/com/moabam/api/application/room/RoomService.java b/src/main/java/com/moabam/api/application/room/RoomService.java index fbd1fc4e..63b2490c 100644 --- a/src/main/java/com/moabam/api/application/room/RoomService.java +++ b/src/main/java/com/moabam/api/application/room/RoomService.java @@ -135,6 +135,7 @@ public void mandateManager(Long managerId, Long roomId, Long memberId) { @Transactional public void deportParticipant(Long managerId, Long roomId, Long memberId) { + validateDeportParticipant(managerId, memberId); Participant managerParticipant = getParticipant(managerId, roomId); Participant memberParticipant = getParticipant(memberId, roomId); validateManagerAuthorization(managerParticipant); @@ -172,6 +173,12 @@ private Participant getParticipant(Long memberId, Long roomId) { .orElseThrow(() -> new NotFoundException(PARTICIPANT_NOT_FOUND)); } + private void validateDeportParticipant(Long managerId, Long memberId) { + if (managerId.equals(memberId)) { + throw new BadRequestException(PARTICIPANT_DEPORT_ERROR); + } + } + private void validateManagerAuthorization(Participant participant) { if (!participant.isManager()) { throw new ForbiddenException(ROOM_MODIFY_UNAUTHORIZED_REQUEST); diff --git a/src/main/java/com/moabam/api/application/room/SearchService.java b/src/main/java/com/moabam/api/application/room/SearchService.java index fafe30d0..5aec7dc1 100644 --- a/src/main/java/com/moabam/api/application/room/SearchService.java +++ b/src/main/java/com/moabam/api/application/room/SearchService.java @@ -147,7 +147,7 @@ public ManageRoomResponse getRoomForModification(Long memberId, Long roomId) { participantResponses.add(ParticipantMapper.toParticipantResponse(member, contributionPoint)); } - return RoomMapper.toManageRoomResponse(room, routineResponses, participantResponses); + return RoomMapper.toManageRoomResponse(room, memberId, routineResponses, participantResponses); } public GetAllRoomsResponse getAllRooms(@Nullable RoomType roomType, @Nullable Long roomId) { diff --git a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java index f80eec07..8282c0ee 100644 --- a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java +++ b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java @@ -99,11 +99,12 @@ public static RoomsHistoryResponse toRoomsHistoryResponse(List routines, + public static ManageRoomResponse toManageRoomResponse(Room room, Long managerId, List routines, List participantResponses) { return ManageRoomResponse.builder() .roomId(room.getId()) .title(room.getTitle()) + .managerId(managerId) .announcement(room.getAnnouncement()) .roomType(room.getRoomType()) .certifyTime(room.getCertifyTime()) diff --git a/src/main/java/com/moabam/api/domain/room/repository/ParticipantSearchRepository.java b/src/main/java/com/moabam/api/domain/room/repository/ParticipantSearchRepository.java index c99a6d48..761ea8c3 100644 --- a/src/main/java/com/moabam/api/domain/room/repository/ParticipantSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/room/repository/ParticipantSearchRepository.java @@ -62,6 +62,7 @@ public List findAllParticipantsByMemberId(Long memberId) { .where( participant.memberId.eq(memberId) ) + .orderBy(participant.createdAt.desc()) .fetch(); } diff --git a/src/main/java/com/moabam/api/dto/room/ManageRoomResponse.java b/src/main/java/com/moabam/api/dto/room/ManageRoomResponse.java index 98f495ae..cbf9c261 100644 --- a/src/main/java/com/moabam/api/dto/room/ManageRoomResponse.java +++ b/src/main/java/com/moabam/api/dto/room/ManageRoomResponse.java @@ -10,6 +10,7 @@ public record ManageRoomResponse( Long roomId, String title, + Long managerId, String announcement, RoomType roomType, int certifyTime, diff --git a/src/main/java/com/moabam/global/error/model/ErrorMessage.java b/src/main/java/com/moabam/global/error/model/ErrorMessage.java index 408e5574..907c756b 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -29,6 +29,7 @@ public enum ErrorMessage { INVALID_REQUEST_URL("잘못된 URL 요청입니다."), INVALID_CERTIFY_TIME("현재 인증 시간이 아닙니다."), CERTIFICATION_NOT_FOUND("인증 정보가 없습니다."), + PARTICIPANT_DEPORT_ERROR("방장은 자신을 추방할 수 없습니다."), LOGIN_FAILED("로그인에 실패했습니다."), REQUEST_FAILED("네트워크 접근 실패입니다."), diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index 265450c4..0577f001 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -887,6 +887,25 @@ void deport_member_success() throws Exception { assertThat(participantSearchRepository.findOne(member.getId(), room.getId())).isEmpty(); } + @DisplayName("방장 본인 추방 시도 - 예외 처리") + @WithMember(id = 1L) + @Test + void deport_self_fail() throws Exception { + // given + Room room = RoomFixture.room(); + + Participant managerParticipant = RoomFixture.participant(room, member.getId()); + managerParticipant.enableManager(); + + roomRepository.save(room); + participantRepository.save(managerParticipant); + + // expected + mockMvc.perform(delete("/rooms/" + room.getId() + "/members/" + member.getId())) + .andExpect(status().isBadRequest()) + .andDo(print()); + } + @DisplayName("방장 위임 성공") @WithMember(id = 1L) @Test