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 9 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 @@ -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,24 +1,43 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved

import lombok.RequiredArgsConstructor;

@RestController
@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 ResponseEntity.status(
SocialAccountSuccess.GET_SOCIAL_ACCOUNT_PLATFORM.getStatus().value())
.body(
BaseResponse.ofSuccess(
SocialAccountSuccess.GET_SOCIAL_ACCOUNT_PLATFORM,
AuthResponse.SocialAccountPlatform.from(socialAccountPlatform)));
}
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved

@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 @@ -15,6 +15,7 @@ public enum AuthSuccess implements SuccessCode {
VERIFY_PHONE_VERIFICATION(HttpStatus.OK, "번호 인증에 성공했습니다."),

CREATE_PHONE_VERIFICATION(HttpStatus.CREATED, "번호 인증 생성에 성공했습니다."),

AUTHENTICATE_SOCIAL_ACCOUNT(HttpStatus.OK, "소셜 로그인에 성공했습니다.");
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved

private final HttpStatus status;
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
@@ -0,0 +1,19 @@
package sopt.makers.authentication.support.code.domain.success;

import static lombok.AccessLevel.PRIVATE;

import sopt.makers.authentication.support.code.base.SuccessCode;

import org.springframework.http.HttpStatus;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor(access = PRIVATE)
public enum UserSuccess implements SuccessCode {
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
;

private final HttpStatus status;
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ private SystemConstant() {}
public static final String PATH_ERROR = "/error";
public static final String PATH_TEST = "/test";

public static final String PATH_USER = API_DEFAULT_PREFIX + "/user";

public static final String PATTERN_ALL = "/**";
public static final String PATTERN_ERROR_PATH = PATH_ERROR + PATTERN_ALL;
public static final String PATTERN_ACTUATOR = PATH_ACTUATOR + PATTERN_ALL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.PATH_USER;

import sopt.makers.authentication.support.constant.JwtConstant;
import sopt.makers.authentication.support.jwt.provider.JwtAuthAccessTokenProvider;
Expand All @@ -28,6 +29,7 @@
@Component
@RequiredArgsConstructor
public class JwtAuthenticationFilter extends OncePerRequestFilter {
private static final String PATH_GET_REGISTER_SOCIAL_PLATFORM = PATH_USER + "/social";

private final JwtAuthAccessTokenProvider authTokenProvider;

Expand Down Expand Up @@ -55,7 +57,8 @@ private boolean isWhiteRequest(final HttpServletRequest request) {
return url.contains(PATH_ACTUATOR)
|| url.contains(PATH_AUTH)
|| url.contains(PATH_ERROR)
|| url.contains(PATH_TEST);
|| url.contains(PATH_TEST)
|| url.contains(PATH_GET_REGISTER_SOCIAL_PLATFORM);
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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,74 @@
package sopt.makers.authentication.usecase.auth.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
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 org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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 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);
}

@Test
void 주어진_Command에_대해_의도한_결과값을_반환한다() {
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
// given
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommandForGoogle =
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
null, TEST_USER_PHONE_FOR_GOOGLE);
GetSocialAccountUsecase.GetSocialAccountPlatformCommand givenCommandForApple =
new GetSocialAccountUsecase.GetSocialAccountPlatformCommand(
null, TEST_USER_PHONE_FOR_APPLE);

// when
GetSocialAccountUsecase.SocialAccountPlatformInfo resultForGoogle =
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommandForGoogle);
GetSocialAccountUsecase.SocialAccountPlatformInfo resultForApple =
getSocialAccountPlatformService.getSocialAccountPlatform(givenCommandForApple);

// then
assertThat(resultForGoogle.platformName()).isEqualTo("GOOGLE");
assertThat(resultForApple.platformName()).isEqualTo("APPLE");
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading