diff --git a/.github/workflows/develop-cd.yml b/.github/workflows/develop-cd.yml index 60bad952..bca6e32e 100644 --- a/.github/workflows/develop-cd.yml +++ b/.github/workflows/develop-cd.yml @@ -53,7 +53,7 @@ jobs: port: 22 username: ${{ secrets.EC2_INSTANCE_USERNAME }} key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} - source: "./.env, ./docker-compose-dev.yml, ./scripts/*, ./nginx/*" + source: "./.env, ./docker-compose-dev.yml, ./scripts/*, ./nginx/*, ./mysql/*" target: "/home/ubuntu/moabam" - name: 파일 세팅 @@ -69,6 +69,8 @@ jobs: chmod +x ./scripts/deploy-dev.sh chmod +x ./scripts/init-letsencrypt.sh chmod +x ./scripts/init-nginx-converter.sh + chmod +x ./mysql/initdb.d/init.sql + chmod +x ./mysql/initdb.d/item-data.sql - name: Github Actions IP 보안그룹에서 삭제 if: always() diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 4d1e85a0..5d953072 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -70,5 +70,7 @@ services: command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_unicode_ci + - --skip-character-set-client-handshake volumes: - /home/ubuntu/moabam/data/mysql:/var/lib/mysql + - /home/ubuntu/moabam/mysql/initdb.d:/docker-entrypoint-initdb.d diff --git a/src/main/resources/sql/schema.sql b/mysql/initdb.d/init.sql similarity index 100% rename from src/main/resources/sql/schema.sql rename to mysql/initdb.d/init.sql diff --git a/src/main/resources/sql/data.sql b/mysql/initdb.d/item-data.sql similarity index 100% rename from src/main/resources/sql/data.sql rename to mysql/initdb.d/item-data.sql 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 c116c1a5..d14228a6 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 fb8bec5f..ed9ea08e 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 c85a70d8..8a16d99b 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -30,6 +30,7 @@ public enum ErrorMessage { INVALID_CERTIFY_TIME("현재 인증 시간이 아닙니다."), CERTIFICATION_NOT_FOUND("인증 정보가 없습니다."), NEED_TO_EXIT_ALL_ROOMS("모든 방에서 나가야 회원 탈퇴가 가능합니다."), + 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