diff --git a/src/main/java/com/softeer/backend/fo_domain/draw/dto/history/DrawHistoryResponseDto.java b/src/main/java/com/softeer/backend/fo_domain/draw/dto/history/DrawHistoryResponseDto.java index 1b01fb3b..f3531e8f 100644 --- a/src/main/java/com/softeer/backend/fo_domain/draw/dto/history/DrawHistoryResponseDto.java +++ b/src/main/java/com/softeer/backend/fo_domain/draw/dto/history/DrawHistoryResponseDto.java @@ -1,5 +1,6 @@ package com.softeer.backend.fo_domain.draw.dto.history; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.experimental.SuperBuilder; @@ -9,5 +10,6 @@ @Data @SuperBuilder public class DrawHistoryResponseDto { + @JsonProperty("isDrawWin") private boolean isDrawWin; } diff --git a/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java b/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java index 941f6657..260357b4 100644 --- a/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java +++ b/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java @@ -78,12 +78,10 @@ public JwtTokenResponseDto handleLogin(LoginRequestDto loginRequestDto, String s // 공유한 사람의 "내가 초대한 친구 수" 추가 // 공유받은 사람은 이미 공유 url로 참여했다고 표시해주기 if (shareCode != null) { - // 공유한 사람의 아이디 - Integer shareUserId = shareUrlInfoRepository.findUserIdByShareUrl(shareCode) - .orElseThrow(() -> new ShareUrlInfoException(ErrorStatus._NOT_FOUND)); - - // 공유한 사람 추첨 기회 추가 - shareInfoRepository.increaseInvitedNumAndRemainDrawCount(shareUserId); + // 공유한 사용자의 userId 조회 및 조건에 따른 로직 실행 + // userId가 null이 아닌 경우에만 실행 + shareUrlInfoRepository.findUserIdByShareUrl(shareCode) + .ifPresent(shareInfoRepository::increaseInvitedNumAndRemainDrawCount); } } // 전화번호가 이미 User DB에 등록되어 있는 경우 diff --git a/src/test/java/com/softeer/backend/fo_domain/user/service/LoginServiceTest.java b/src/test/java/com/softeer/backend/fo_domain/user/service/LoginServiceTest.java index 6d3223e7..23252019 100644 --- a/src/test/java/com/softeer/backend/fo_domain/user/service/LoginServiceTest.java +++ b/src/test/java/com/softeer/backend/fo_domain/user/service/LoginServiceTest.java @@ -83,7 +83,7 @@ void testHandleLogin_UnverifiedCode() { @DisplayName("전화번호가 DB에 없는 경우 새로운 User 등록 및 관련 정보 생성") void testHandleLogin_NewUserRegistration() { // given - when(shareUrlInfoRepository.findUserIdByShareUrl(anyString())).thenReturn(Optional.of(1)); + lenient().when(shareUrlInfoRepository.findUserIdByShareUrl(anyString())).thenReturn(Optional.of(1)); when(userRepository.existsByPhoneNumber(phoneNumber)).thenReturn(false); when(userRepository.save(any(User.class))).thenAnswer(invocation -> { User user = invocation.getArgument(0); @@ -177,19 +177,4 @@ void testHandleLogin_SharedUrl() { assertThat(response.getAccessToken()).isEqualTo("accessToken"); assertThat(response.getRefreshToken()).isEqualTo("refreshToken"); } - - @Test - @DisplayName("공유 URL이 유효하지 않은 경우 예외 발생") - void testHandleLogin_InvalidShareUrl() { - // given - when(userRepository.existsByPhoneNumber(phoneNumber)).thenReturn(false); - when(userRepository.save(any(User.class))).thenReturn(User.builder().id(1).build()); - when(shareUrlInfoRepository.findUserIdByShareUrl(shareCode)).thenReturn(Optional.empty()); - - // when / then - assertThatThrownBy(() -> loginService.handleLogin(loginRequestDto, shareCode)) - .isInstanceOf(ShareUrlInfoException.class) - .extracting(ex -> ((ShareUrlInfoException) ex).getCode()) - .isEqualTo(ErrorStatus._NOT_FOUND); - } }