diff --git a/src/main/java/net/teumteum/meeting/domain/response/MeetingParticipantsForReviewResponse.java b/src/main/java/net/teumteum/meeting/domain/response/MeetingParticipantsForReviewResponse.java new file mode 100644 index 0000000..8347c4e --- /dev/null +++ b/src/main/java/net/teumteum/meeting/domain/response/MeetingParticipantsForReviewResponse.java @@ -0,0 +1,30 @@ +package net.teumteum.meeting.domain.response; + +import java.util.List; +import net.teumteum.user.domain.User; + +public record MeetingParticipantsForReviewResponse( + List participants +) { + + public static MeetingParticipantsForReviewResponse of(List users) { + return new MeetingParticipantsForReviewResponse( + users.stream() + .map(user -> new MeetingParticipantForReviewResponse( + user.getId(), + user.getCharacterId(), + user.getName(), + user.getJob().getDetailJobClass())) + .toList() + ); + } + + public record MeetingParticipantForReviewResponse( + Long id, + Long characterId, + String name, + String job + ) { + + } +} diff --git a/src/main/java/net/teumteum/user/service/UserService.java b/src/main/java/net/teumteum/user/service/UserService.java index 5a4448b..8429d05 100644 --- a/src/main/java/net/teumteum/user/service/UserService.java +++ b/src/main/java/net/teumteum/user/service/UserService.java @@ -144,10 +144,11 @@ public InterestQuestionResponse getInterestQuestionByUserIds(List userIds, } private void checkUserExistence(Authenticated authenticated, String oauthId) { - userRepository.findByAuthenticatedAndOAuthId(authenticated, oauthId) - .ifPresent(user -> { + boolean userExists = userRepository.findByAuthenticatedAndOAuthId(authenticated, oauthId).isPresent(); + Assert.isTrue(!userExists, () -> { throw new IllegalArgumentException("일치하는 user 가 이미 존재합니다."); - }); + } + ); } private void checkMeetingExistence(Long meetingId) { diff --git a/src/test/java/net/teumteum/unit/user/controller/UserControllerTest.java b/src/test/java/net/teumteum/unit/user/controller/UserControllerTest.java index 9963a8c..f1e76e8 100644 --- a/src/test/java/net/teumteum/unit/user/controller/UserControllerTest.java +++ b/src/test/java/net/teumteum/unit/user/controller/UserControllerTest.java @@ -106,6 +106,26 @@ void Register_user_card_with_201_created() throws Exception { .andExpect(jsonPath("$.refreshToken").value(VALID_REFRESH_TOKEN)); } + @Test + @DisplayName("이미 카드 등록한 사용자의 등록 요청값이 주어지면, 400 Bad Request을 반환한다.") + void Return_400_bad_request_if_user_already_exist() throws Exception { + // given + UserRegisterRequest request = RequestFixture.userRegisterRequest(user); + + given(userService.register(any(UserRegisterRequest.class))) + .willThrow(new IllegalArgumentException("일치하는 user 가 이미 존재합니다.")); + + // when && then + mockMvc.perform(post("/users") + .content(objectMapper.writeValueAsString(request)) + .contentType(APPLICATION_JSON) + .with(csrf()) + .header(AUTHORIZATION, VALID_ACCESS_TOKEN)) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("일치하는 user 가 이미 존재합니다.")); + } + @Test @DisplayName("유효하지 않은 사용자의 등록 요청값이 주어지면, 400 Bad Request 상태값을 반환한다.") void Register_user_card_with_400_bad_request() throws Exception { @@ -144,6 +164,26 @@ void Withdraw_user_with_200_ok() throws Exception { .andDo(print()) .andExpect(status().isOk()); } + + @Test + @DisplayName("회원 탈퇴 하고자 하는 회원이 존재하지 않으면") + void Return_400_bad_request_if_user_is_not_exist() throws Exception { + // given + UserWithdrawRequest request + = RequestFixture.userWithdrawRequest(List.of("쓰지 않는 앱이에요", "오류가 생겨서 쓸 수 없어요")); + + doThrow(new IllegalArgumentException("일치하는 user가 이미 존재합니다.")).when(userService).withdraw(any( + UserWithdrawRequest.class), anyLong()); + + // when && then + mockMvc.perform(post("/users/withdraws") + .content(objectMapper.writeValueAsString(request)) + .contentType(APPLICATION_JSON) + .with(csrf()) + .header(AUTHORIZATION, VALID_ACCESS_TOKEN)) + .andDo(print()) + .andExpect(status().isBadRequest()); + } } @Nested diff --git a/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java b/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java index cda176b..b92508f 100644 --- a/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java +++ b/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java @@ -154,6 +154,24 @@ void If_valid_user_withdraw_request_withdraw_user() { verify(redisService, times(1)).deleteData(anyString()); verify(withdrawReasonRepository, times(1)).saveAll(any()); } + + @Test + @DisplayName("유저 id에 해당하는 유저가 존재하지 않는 경우, 400 Bad Request 을 반환한다.") + void Return_400_bad_request_if_user_is_not_exist() { + // given + UserWithdrawRequest request + = RequestFixture.userWithdrawRequest(List.of("쓰지 않는 앱이에요", "오류가 생겨서 쓸 수 없어요")); + + long userId = 1L; + + given(userRepository.findById(anyLong())) + .willThrow(new IllegalArgumentException("userId 에 해당하는 user를 찾을 수 없습니다.")); + + // When & Then + assertThatThrownBy(() -> userService.withdraw(request, userId)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("userId 에 해당하는 user를 찾을 수 없습니다."); + } } @Nested