Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#17] 가입 계정 플랫폼 조회 기능 구현 #27

Merged
merged 15 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ public ResponseEntity<BaseResponse<?>> 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));
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface SocialAccountApi {
ResponseEntity<BaseResponse<?>> updateSocialAccount(
SocialAccountRequest.UpdateSocialAccount socialAccountInfo);

ResponseEntity<BaseResponse<?>> getRegisterSocialAccountPlatform(String name, String phone);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BaseResponse<?>> 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<BaseResponse<?>> updateSocialAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sopt.makers.authentication.support.constant;

import java.util.List;

public final class SystemConstant {
private SystemConstant() {}

Expand All @@ -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<String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
4 changes: 4 additions & 0 deletions src/main/resources/jpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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));
}
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
}
Loading