Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
Browse files Browse the repository at this point in the history
…to fix/#175-fix-member-delete-error

# Conflicts:
#	src/main/java/com/moabam/global/error/model/ErrorMessage.java
#	src/main/resources/config
  • Loading branch information
parksey committed Nov 29, 2023
2 parents 68da68f + bbf3974 commit 3f66fd4
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/develop-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 파일 세팅
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ public static RoomsHistoryResponse toRoomsHistoryResponse(List<RoomHistoryRespon
.build();
}

public static ManageRoomResponse toManageRoomResponse(Room room, List<RoutineResponse> routines,
public static ManageRoomResponse toManageRoomResponse(Room room, Long managerId, List<RoutineResponse> routines,
List<ParticipantResponse> participantResponses) {
return ManageRoomResponse.builder()
.roomId(room.getId())
.title(room.getTitle())
.managerId(managerId)
.announcement(room.getAnnouncement())
.roomType(room.getRoomType())
.certifyTime(room.getCertifyTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public List<Participant> findAllParticipantsByMemberId(Long memberId) {
.where(
participant.memberId.eq(memberId)
)
.orderBy(participant.createdAt.desc())
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public record ManageRoomResponse(
Long roomId,
String title,
Long managerId,
String announcement,
RoomType roomType,
int certifyTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("네트워크 접근 실패입니다."),
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/moabam/api/presentation/RoomControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f66fd4

Please sign in to comment.