diff --git a/src/main/java/sopt/makers/authentication/application/auth/api/AuthApiController.java b/src/main/java/sopt/makers/authentication/application/auth/api/AuthApiController.java index 50609ef..7b92a6a 100644 --- a/src/main/java/sopt/makers/authentication/application/auth/api/AuthApiController.java +++ b/src/main/java/sopt/makers/authentication/application/auth/api/AuthApiController.java @@ -44,10 +44,8 @@ public ResponseEntity> verifyPhoneVerification( @RequestBody AuthRequest.VerifyPhoneVerification phoneVerification) { VerifyPhoneVerificationUsecase.VerifyVerificationResult result = verifyVerificationUsecase.verify(phoneVerification.toCommand()); - return ResponseEntity.status(AuthSuccess.VERIFY_PHONE_VERIFICATION.getStatus().value()) - .body( - BaseResponse.ofSuccess( - AuthSuccess.VERIFY_PHONE_VERIFICATION, AuthResponse.VerifyResult.from(result))); + return ResponseUtil.success( + AuthSuccess.VERIFY_PHONE_VERIFICATION, AuthResponse.VerifyResult.from(result)); } @Override diff --git a/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApi.java b/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApi.java index 0585a45..31182c2 100644 --- a/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApi.java +++ b/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApi.java @@ -8,4 +8,6 @@ public interface SocialAccountApi { ResponseEntity> updateSocialAccount( SocialAccountRequest.UpdateSocialAccount socialAccountInfo); + + ResponseEntity> getRegisterSocialAccountPlatform(String name, String phone); } diff --git a/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApiController.java b/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApiController.java index a9d5bb2..335bc5b 100644 --- a/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApiController.java +++ b/src/main/java/sopt/makers/authentication/application/auth/api/SocialAccountApiController.java @@ -1,14 +1,18 @@ package sopt.makers.authentication.application.auth.api; import sopt.makers.authentication.application.auth.dto.request.SocialAccountRequest; +import sopt.makers.authentication.application.auth.dto.response.AuthResponse; import sopt.makers.authentication.support.code.domain.success.SocialAccountSuccess; import sopt.makers.authentication.support.common.api.BaseResponse; import sopt.makers.authentication.support.util.ResponseUtil; +import sopt.makers.authentication.usecase.auth.port.in.GetSocialAccountUsecase; import sopt.makers.authentication.usecase.auth.port.in.UpdateSocialAccountUsecase; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import lombok.RequiredArgsConstructor; @@ -17,8 +21,24 @@ @RequestMapping("/api/v1/social/accounts") @RequiredArgsConstructor public class SocialAccountApiController implements SocialAccountApi { + private final GetSocialAccountUsecase getSocialAccountUsecase; private final UpdateSocialAccountUsecase updateSocialAccountUsecase; + @Override + @GetMapping("/platform") + public ResponseEntity> getRegisterSocialAccountPlatform( + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "phone") String phone) { + GetSocialAccountUsecase.GetSocialAccountPlatformCommand command = + new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(name, phone); + GetSocialAccountUsecase.SocialAccountPlatformInfo socialAccountPlatform = + getSocialAccountUsecase.getSocialAccountPlatform(command); + + return ResponseUtil.success( + SocialAccountSuccess.GET_SOCIAL_ACCOUNT_PLATFORM, + AuthResponse.SocialAccountPlatform.from(socialAccountPlatform)); + } + @Override @PatchMapping public ResponseEntity> updateSocialAccount( diff --git a/src/main/java/sopt/makers/authentication/application/auth/dto/response/AuthResponse.java b/src/main/java/sopt/makers/authentication/application/auth/dto/response/AuthResponse.java index 0838560..a032ec8 100644 --- a/src/main/java/sopt/makers/authentication/application/auth/dto/response/AuthResponse.java +++ b/src/main/java/sopt/makers/authentication/application/auth/dto/response/AuthResponse.java @@ -2,6 +2,7 @@ import static lombok.AccessLevel.PRIVATE; +import sopt.makers.authentication.usecase.auth.port.in.GetSocialAccountUsecase; import sopt.makers.authentication.usecase.auth.port.in.VerifyPhoneVerificationUsecase; import com.fasterxml.jackson.annotation.JsonProperty; @@ -32,4 +33,11 @@ public static AuthenticateSocialAuthInfoForApp of(String accessToken, String ref return new AuthenticateSocialAuthInfoForApp(accessToken, refreshToken); } } + + public record SocialAccountPlatform(@JsonProperty("platform") String platformName) { + public static SocialAccountPlatform from( + GetSocialAccountUsecase.SocialAccountPlatformInfo info) { + return new SocialAccountPlatform(info.platformName()); + } + } } diff --git a/src/main/java/sopt/makers/authentication/support/code/domain/success/AuthSuccess.java b/src/main/java/sopt/makers/authentication/support/code/domain/success/AuthSuccess.java index ed90b05..4b0907a 100644 --- a/src/main/java/sopt/makers/authentication/support/code/domain/success/AuthSuccess.java +++ b/src/main/java/sopt/makers/authentication/support/code/domain/success/AuthSuccess.java @@ -12,10 +12,13 @@ @Getter @RequiredArgsConstructor(access = PRIVATE) public enum AuthSuccess implements SuccessCode { + // 200 VERIFY_PHONE_VERIFICATION(HttpStatus.OK, "번호 인증에 성공했습니다."), + AUTHENTICATE_SOCIAL_ACCOUNT(HttpStatus.OK, "소셜 로그인에 성공했습니다."), + // 201 CREATE_PHONE_VERIFICATION(HttpStatus.CREATED, "번호 인증 생성에 성공했습니다."), - AUTHENTICATE_SOCIAL_ACCOUNT(HttpStatus.OK, "소셜 로그인에 성공했습니다."); + ; private final HttpStatus status; private final String message; diff --git a/src/main/java/sopt/makers/authentication/support/code/domain/success/SocialAccountSuccess.java b/src/main/java/sopt/makers/authentication/support/code/domain/success/SocialAccountSuccess.java index bd1c9af..069b912 100644 --- a/src/main/java/sopt/makers/authentication/support/code/domain/success/SocialAccountSuccess.java +++ b/src/main/java/sopt/makers/authentication/support/code/domain/success/SocialAccountSuccess.java @@ -11,6 +11,7 @@ @Getter @RequiredArgsConstructor(access = PRIVATE) public enum SocialAccountSuccess implements SuccessCode { + GET_SOCIAL_ACCOUNT_PLATFORM(HttpStatus.OK, "가입 계정 플랫폼 정보 조회에 성공했습니다."), UPDATE_SOCIAL_ACCOUNT(HttpStatus.OK, "소셜 계정 변경에 성공했습니다."); private final HttpStatus status; diff --git a/src/main/java/sopt/makers/authentication/support/constant/SystemConstant.java b/src/main/java/sopt/makers/authentication/support/constant/SystemConstant.java index 1d345be..1238617 100644 --- a/src/main/java/sopt/makers/authentication/support/constant/SystemConstant.java +++ b/src/main/java/sopt/makers/authentication/support/constant/SystemConstant.java @@ -1,5 +1,7 @@ package sopt.makers.authentication.support.constant; +import java.util.List; + public final class SystemConstant { private SystemConstant() {} @@ -9,10 +11,15 @@ private SystemConstant() {} public static final String API_DEFAULT_PREFIX = API_PATH_PREFIX + API_VERSION; - public static final String PATH_ACTUATOR = "/actuator"; - public static final String PATH_AUTH = "/auth"; - public static final String PATH_ERROR = "/error"; - public static final String PATH_TEST = "/test"; + private static final String PATH_ACTUATOR = "/actuator"; + private static final String PATH_AUTH = API_DEFAULT_PREFIX + "/auth"; + private static final String PATH_ERROR = "/error"; + private static final String PATH_TEST = "/test"; + private static final String PATH_GET_REGISTER_SOCIAL_PLATFORM = + API_PATH_PREFIX + "/social/accounts/social"; + + public static List WHITE_PATHS = + List.of(PATH_ACTUATOR, PATH_AUTH, PATH_GET_REGISTER_SOCIAL_PLATFORM, PATH_ERROR, PATH_TEST); public static final String PATTERN_ALL = "/**"; public static final String PATTERN_ERROR_PATH = PATH_ERROR + PATTERN_ALL; diff --git a/src/main/java/sopt/makers/authentication/support/security/filter/JwtAuthenticationFilter.java b/src/main/java/sopt/makers/authentication/support/security/filter/JwtAuthenticationFilter.java index b03d046..b1cb909 100644 --- a/src/main/java/sopt/makers/authentication/support/security/filter/JwtAuthenticationFilter.java +++ b/src/main/java/sopt/makers/authentication/support/security/filter/JwtAuthenticationFilter.java @@ -1,9 +1,6 @@ package sopt.makers.authentication.support.security.filter; -import static sopt.makers.authentication.support.constant.SystemConstant.PATH_ACTUATOR; -import static sopt.makers.authentication.support.constant.SystemConstant.PATH_AUTH; -import static sopt.makers.authentication.support.constant.SystemConstant.PATH_ERROR; -import static sopt.makers.authentication.support.constant.SystemConstant.PATH_TEST; +import static sopt.makers.authentication.support.constant.SystemConstant.WHITE_PATHS; import sopt.makers.authentication.support.constant.JwtConstant; import sopt.makers.authentication.support.jwt.provider.JwtAuthAccessTokenProvider; @@ -52,10 +49,7 @@ public boolean shouldNotFilter(HttpServletRequest request) { private boolean isWhiteRequest(final HttpServletRequest request) { String url = request.getRequestURL().toString(); - return url.contains(PATH_ACTUATOR) - || url.contains(PATH_AUTH) - || url.contains(PATH_ERROR) - || url.contains(PATH_TEST); + return WHITE_PATHS.stream().anyMatch(url::contains); } /** diff --git a/src/main/java/sopt/makers/authentication/usecase/auth/port/in/GetSocialAccountUsecase.java b/src/main/java/sopt/makers/authentication/usecase/auth/port/in/GetSocialAccountUsecase.java new file mode 100644 index 0000000..833f1d9 --- /dev/null +++ b/src/main/java/sopt/makers/authentication/usecase/auth/port/in/GetSocialAccountUsecase.java @@ -0,0 +1,10 @@ +package sopt.makers.authentication.usecase.auth.port.in; + +public interface GetSocialAccountUsecase { + + SocialAccountPlatformInfo getSocialAccountPlatform(GetSocialAccountPlatformCommand command); + + record GetSocialAccountPlatformCommand(String name, String phone) {} + + record SocialAccountPlatformInfo(String platformName) {} +} diff --git a/src/main/java/sopt/makers/authentication/usecase/auth/service/GetSocialAccountPlatformService.java b/src/main/java/sopt/makers/authentication/usecase/auth/service/GetSocialAccountPlatformService.java new file mode 100644 index 0000000..103320f --- /dev/null +++ b/src/main/java/sopt/makers/authentication/usecase/auth/service/GetSocialAccountPlatformService.java @@ -0,0 +1,24 @@ +package sopt.makers.authentication.usecase.auth.service; + +import sopt.makers.authentication.domain.auth.AuthPlatform; +import sopt.makers.authentication.domain.user.User; +import sopt.makers.authentication.usecase.auth.port.in.GetSocialAccountUsecase; +import sopt.makers.authentication.usecase.auth.port.out.UserRepository; + +import org.springframework.stereotype.Service; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class GetSocialAccountPlatformService implements GetSocialAccountUsecase { + private final UserRepository userRepository; + + @Override + public SocialAccountPlatformInfo getSocialAccountPlatform( + GetSocialAccountPlatformCommand command) { + User user = userRepository.findByPhone(command.phone()); + AuthPlatform authPlatform = user.getSocialAccount().authPlatformType(); + return new SocialAccountPlatformInfo(authPlatform.name()); + } +} diff --git a/src/main/resources/jpa.yaml b/src/main/resources/jpa.yaml index ea449bd..7193da1 100644 --- a/src/main/resources/jpa.yaml +++ b/src/main/resources/jpa.yaml @@ -5,6 +5,8 @@ spring: jpa: hibernate: ddl-auto: none + database-platform: ${JPA_DATABASE_PLATFORM} + database: ${JPA_DATABASE} --- spring.config.activate.on-profile: local spring: @@ -15,6 +17,8 @@ spring: hibernate: show_sql: true format_sql: true + database-platform: ${JPA_DATABASE_PLATFORM} + database: ${JPA_DATABASE} --- spring.config.activate.on-profile: test diff --git a/src/test/java/sopt/makers/authentication/usecase/auth/service/GetSocialAccountPlatformServiceTest.java b/src/test/java/sopt/makers/authentication/usecase/auth/service/GetSocialAccountPlatformServiceTest.java new file mode 100644 index 0000000..72edadb --- /dev/null +++ b/src/test/java/sopt/makers/authentication/usecase/auth/service/GetSocialAccountPlatformServiceTest.java @@ -0,0 +1,85 @@ +package sopt.makers.authentication.usecase.auth.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import sopt.makers.authentication.domain.auth.AuthPlatform; +import sopt.makers.authentication.domain.auth.SocialAccount; +import sopt.makers.authentication.domain.user.User; +import sopt.makers.authentication.usecase.auth.port.in.GetSocialAccountUsecase; +import sopt.makers.authentication.usecase.auth.port.out.UserRepository; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; + +@SpringBootTest +@ActiveProfiles("local") +@TestPropertySource(locations = {"classpath:env/local.env"}) +class GetSocialAccountPlatformServiceTest { + private static final String PLATFORM_NAME_GOOGLE = "GOOGLE"; + private static final String PLATFORM_NAME_APPLE = "APPLE"; + private static final String TEST_AUTH_ID = "test"; + private static final String TEST_USER_PHONE_FOR_GOOGLE = "01012345678"; + private static final String TEST_USER_PHONE_FOR_APPLE = "01087654321"; + + @MockBean UserRepository userRepository; + + @Autowired GetSocialAccountPlatformService getSocialAccountPlatformService; + + @BeforeEach + void setMockUser() { + User mockedUserForGoogle = mock(User.class); + User mockedUserForApple = mock(User.class); + SocialAccount mockedSocialAccountForGoogle = mock(SocialAccount.class); + SocialAccount mockedSocialAccountForApple = mock(SocialAccount.class); + + given(mockedSocialAccountForGoogle.authPlatformId()).willReturn(TEST_AUTH_ID); + given(mockedSocialAccountForApple.authPlatformId()).willReturn(TEST_AUTH_ID); + given(mockedSocialAccountForGoogle.authPlatformType()).willReturn(AuthPlatform.GOOGLE); + given(mockedSocialAccountForApple.authPlatformType()).willReturn(AuthPlatform.APPLE); + + given(mockedUserForGoogle.getSocialAccount()).willReturn(mockedSocialAccountForGoogle); + given(mockedUserForApple.getSocialAccount()).willReturn(mockedSocialAccountForApple); + + when(userRepository.findByPhone(TEST_USER_PHONE_FOR_GOOGLE)).thenReturn(mockedUserForGoogle); + when(userRepository.findByPhone(TEST_USER_PHONE_FOR_APPLE)).thenReturn(mockedUserForApple); + } + + @ParameterizedTest(name = "({index}) command : {0} -> result : {1}") + @DisplayName("주어진 Command에 대해 의도한 결과값을 반환한다") + @MethodSource("argsForGetPlatformInfoTest") + void 주어진_Command에_대해_의도한_결과값을_반환한다( + // given + GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommand, String expectedResult) { + // when + GetSocialAccountUsecase.SocialAccountPlatformInfo result = + getSocialAccountPlatformService.getSocialAccountPlatform(givenCommand); + + // then + assertThat(result.platformName()).isEqualTo(expectedResult); + } + + static Stream argsForGetPlatformInfoTest() { + return Stream.of( + Arguments.of( + new GetSocialAccountUsecase.GetSocialAccountPlatformCommand( + null, TEST_USER_PHONE_FOR_GOOGLE), + PLATFORM_NAME_GOOGLE), + Arguments.of( + new GetSocialAccountUsecase.GetSocialAccountPlatformCommand( + null, TEST_USER_PHONE_FOR_APPLE), + PLATFORM_NAME_APPLE)); + } +}