From a0b3bf12b8f7b3a2169142ea89f2a50cf2904d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Thu, 3 Oct 2024 21:34:01 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=EC=97=90=20=EA=B0=80=EC=9E=85=ED=95=9C=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EC=9D=B4=20=EC=95=84=EB=8B=8C=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/exception/AuthErrorMessage.java | 2 +- .../backend/auth/implement/LoginManager.java | 6 ++++++ .../auth/implement/LoginManagerTest.java | 21 +++++++++++++++---- .../backend/common/fixture/MemberFixture.java | 7 +++++++ .../backend/member/domain/MemberTest.java | 17 --------------- 5 files changed, 31 insertions(+), 22 deletions(-) delete mode 100644 backend/src/test/java/mouda/backend/member/domain/MemberTest.java diff --git a/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java b/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java index 85e3a06c0..4e442875c 100644 --- a/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java +++ b/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java @@ -18,7 +18,7 @@ public enum AuthErrorMessage { KAKAO_CONNECT_TIMEOUT("커넥션 타임아웃 되었습니다."), DARAKBANG_NOT_ENTERED("가입한 다락방이 아닙니다."), MEMBER_NOT_FOUND("회원가입 이력을 찾을 수 없습니다."), - ; + KAKAO_CANNOT_SIGNUP("기존 카카오 로그인 이력이 있는 사용자만 이용할 수 있는 서비스입니다. 새로운 회원은 다른 로그인 서비스를 이용해주세요."); private final String message; } diff --git a/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java b/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java index 31b453ead..a929b3b90 100644 --- a/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java +++ b/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java @@ -2,9 +2,12 @@ import java.util.Optional; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; import lombok.RequiredArgsConstructor; +import mouda.backend.auth.exception.AuthErrorMessage; +import mouda.backend.auth.exception.AuthException; import mouda.backend.auth.implement.jwt.AccessTokenProvider; import mouda.backend.member.domain.LoginDetail; import mouda.backend.member.domain.Member; @@ -27,6 +30,9 @@ public String processSocialLogin(OauthType oauthType, String socialLoginId) { return accessTokenProvider.provide(member.get()); } + if (oauthType == OauthType.KAKAO) { + throw new AuthException(HttpStatus.BAD_REQUEST, AuthErrorMessage.KAKAO_CANNOT_SIGNUP); + } Member newMember = Member.builder() .nickname("nickname") .loginDetail(new LoginDetail(oauthType, socialLoginId)) diff --git a/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java b/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java index e9681b27f..b50a0f690 100644 --- a/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java +++ b/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java @@ -4,11 +4,13 @@ import java.util.Optional; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import mouda.backend.auth.exception.AuthException; import mouda.backend.common.fixture.MemberFixture; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -40,18 +42,29 @@ void processSocialLogin() { assertThat(foundMember.get()).isEqualTo(member); } - @DisplayName("주어진 카카오 id로 로그인을 시도한다 -> 회원가입한 이력이 없는 경우") + @DisplayName("이전에 카카오로 가입한 적이 있는 사용자가 카카오 로그인을 시도하면 성공적으로 로그인한다.") @Test - void processSocialLoginWithSignUp() { + void processSocialLoginWhoSignedUpBefore() { // given String kakaoId = "456"; + Member anna = MemberFixture.getAnna(kakaoId); + memberRepository.save(anna); // when String token = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); // then assertThat(token).isNotNull(); - Optional newMember = memberRepository.findByLoginDetail_SocialLoginId(kakaoId); - assertThat(newMember.isPresent()).isTrue(); + } + + @DisplayName("이전에 카카오로 가입한 적이 없는 사용자가 카카오 로그인을 시도하면 예외를 발생시킨다.") + @Test + void processSocialLoginWhoDoesNotSignedUpBefore() { + // given + String kakaoId = "456"; + + // when & then + Assertions.assertThatThrownBy(() -> loginManager.processSocialLogin(OauthType.KAKAO, kakaoId)) + .isInstanceOf(AuthException.class); } } diff --git a/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java b/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java index 535596ce6..0dc966f1f 100644 --- a/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java +++ b/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java @@ -20,6 +20,13 @@ public static Member getAnna() { .build(); } + public static Member getAnna(String socialLoginId) { + return Member.builder() + .nickname("anna") + .loginDetail(new LoginDetail(OauthType.KAKAO, socialLoginId)) + .build(); + } + public static Member getTebah() { return Member.builder() .nickname("tebah") diff --git a/backend/src/test/java/mouda/backend/member/domain/MemberTest.java b/backend/src/test/java/mouda/backend/member/domain/MemberTest.java deleted file mode 100644 index 078963964..000000000 --- a/backend/src/test/java/mouda/backend/member/domain/MemberTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package mouda.backend.member.domain; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import mouda.backend.common.fixture.MemberFixture; - -class MemberTest { - - @DisplayName("회원을 정상적으로 생성한다.") - @Test - void createMember() { - assertDoesNotThrow(MemberFixture::getAnna); - } -} From 2a46dec188578988bd558e21faa321e6f458fd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Thu, 3 Oct 2024 22:43:26 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/business/AppleAuthService.java | 9 ++-- .../backend/auth/business/AuthService.java | 4 +- .../auth/business/GoogleAuthService.java | 8 +++- .../auth/business/KakaoAuthService.java | 2 +- .../backend/auth/implement/LoginManager.java | 9 ++++ .../controller/AuthController.java | 5 ++- .../controller/swagger/AuthSwagger.java | 5 ++- .../presentation/request/OauthRequest.java | 3 ++ .../response/LegacyOauthRequest.java | 11 +++++ .../backend/member/domain/LoginDetail.java | 17 ++++++++ .../member/implement/MemberWriter.java | 5 +++ .../infrastructure/MemberRepository.java | 15 +++++++ .../auth/business/AppleAuthServiceTest.java | 43 +++++++++++++++++-- 13 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java diff --git a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java index 0c52f2857..9c0bc6fd9 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java @@ -5,7 +5,7 @@ import lombok.RequiredArgsConstructor; import mouda.backend.auth.implement.AppleOauthManager; import mouda.backend.auth.implement.LoginManager; -import mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.presentation.response.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -18,10 +18,13 @@ public class AppleAuthService implements AuthService { private final LoginManager loginManager; @Override - public LoginResponse oauthLogin(OauthRequest oauthRequest) { + public LoginResponse oauthLogin(LegacyOauthRequest oauthRequest) { String socialLoginId = oauthManager.getSocialLoginId(oauthRequest.code()); + if (oauthRequest.memberId() != null) { + String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.APPLE, socialLoginId); + return new LoginResponse(accessToken); + } String accessToken = loginManager.processSocialLogin(OauthType.APPLE, socialLoginId); - return new LoginResponse(accessToken); } diff --git a/backend/src/main/java/mouda/backend/auth/business/AuthService.java b/backend/src/main/java/mouda/backend/auth/business/AuthService.java index 8c5c4fd9f..acdcb9546 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AuthService.java @@ -1,12 +1,12 @@ package mouda.backend.auth.business; -import mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.presentation.response.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; public interface AuthService { - LoginResponse oauthLogin(OauthRequest oauthRequest); + LoginResponse oauthLogin(LegacyOauthRequest oauthRequest); Member findMember(String token); diff --git a/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java index 91a89b8b1..07d52abe5 100644 --- a/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java @@ -5,7 +5,7 @@ import lombok.RequiredArgsConstructor; import mouda.backend.auth.implement.GoogleOauthManager; import mouda.backend.auth.implement.LoginManager; -import mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.presentation.response.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -18,9 +18,13 @@ public class GoogleAuthService implements AuthService { private final LoginManager loginManager; @Override - public LoginResponse oauthLogin(OauthRequest oauthRequest) { + public LoginResponse oauthLogin(LegacyOauthRequest oauthRequest) { String memberName = googleOauthManager.getMemberName(oauthRequest.code()); String socialLoginId = googleOauthManager.getSocialLoginId(oauthRequest.code()); + if (oauthRequest.memberId() != null) { + String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.GOOGLE, socialLoginId); + return new LoginResponse(accessToken); + } String accessToken = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); return new LoginResponse(accessToken); } diff --git a/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java b/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java index 38806cf60..71286a8d6 100644 --- a/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java @@ -16,7 +16,7 @@ @Service @RequiredArgsConstructor -public class KakaoAuthService implements AuthService { +public class KakaoAuthService { private final AccessTokenProvider accessTokenProvider; private final KakaoOauthManager oauthManager; diff --git a/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java b/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java index a929b3b90..caa6f287e 100644 --- a/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java +++ b/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java @@ -12,6 +12,7 @@ import mouda.backend.member.domain.LoginDetail; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; +import mouda.backend.member.implement.MemberFinder; import mouda.backend.member.implement.MemberWriter; import mouda.backend.member.infrastructure.MemberRepository; @@ -22,6 +23,7 @@ public class LoginManager { private final MemberRepository memberRepository; private final AccessTokenProvider accessTokenProvider; private final MemberWriter memberWriter; + private final MemberFinder memberFinder; public String processSocialLogin(OauthType oauthType, String socialLoginId) { Optional member = memberRepository.findByLoginDetail_SocialLoginId(socialLoginId); @@ -41,4 +43,11 @@ public String processSocialLogin(OauthType oauthType, String socialLoginId) { return accessTokenProvider.provide(newMember); } + + public String updateOauth(long memberId, OauthType oauthType, String socialLoginId) { + Member member = memberFinder.find(memberId); + memberWriter.updateLoginDetail(memberId, oauthType, socialLoginId); + + return accessTokenProvider.provide(member); + } } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java index 43a53a431..5ad746b93 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java @@ -13,6 +13,7 @@ import mouda.backend.auth.business.KakaoAuthService; import mouda.backend.auth.presentation.controller.swagger.AuthSwagger; import mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.presentation.response.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.common.response.RestResponse; @@ -44,7 +45,7 @@ public ResponseEntity> loginBasicOauth() { @Override @PostMapping("/google/oauth") - public ResponseEntity> loginGoogleOauth(@RequestBody OauthRequest oauthRequest) { + public ResponseEntity> loginGoogleOauth(@RequestBody LegacyOauthRequest oauthRequest) { LoginResponse response = googleAuthService.oauthLogin(oauthRequest); return ResponseEntity.ok().body(new RestResponse<>(response)); @@ -52,7 +53,7 @@ public ResponseEntity> loginGoogleOauth(@RequestBody @Override @PostMapping("/apple/oauth") - public ResponseEntity> loginAppleOauth(@RequestBody OauthRequest oauthRequest) { + public ResponseEntity> loginAppleOauth(@RequestBody LegacyOauthRequest oauthRequest) { LoginResponse response = appleAuthService.oauthLogin(oauthRequest); return ResponseEntity.ok().body(new RestResponse<>(response)); diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java index eee946873..904f8bc21 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.presentation.response.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.common.response.RestResponse; @@ -28,11 +29,11 @@ public interface AuthSwagger { @ApiResponses({ @ApiResponse(responseCode = "200", description = "로그인 성공!"), }) - ResponseEntity> loginAppleOauth(@RequestBody OauthRequest oauthRequest); + ResponseEntity> loginAppleOauth(@RequestBody LegacyOauthRequest oauthRequest); @Operation(summary = "구글 oauth 로그인", description = "구글 Oauth Code 를 사용하여 로그인한다(accessToken 발급).") @ApiResponses({ @ApiResponse(responseCode = "200", description = "로그인 성공!"), }) - ResponseEntity> loginGoogleOauth(@RequestBody OauthRequest oauthRequest); + ResponseEntity> loginGoogleOauth(@RequestBody LegacyOauthRequest oauthRequest); } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/request/OauthRequest.java b/backend/src/main/java/mouda/backend/auth/presentation/request/OauthRequest.java index 42b8a8491..0dac0ef4f 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/request/OauthRequest.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/request/OauthRequest.java @@ -1,6 +1,9 @@ package mouda.backend.auth.presentation.request; +import jakarta.validation.constraints.NotNull; + public record OauthRequest( + @NotNull String code ) { } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java b/backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java new file mode 100644 index 000000000..2e3d4660b --- /dev/null +++ b/backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java @@ -0,0 +1,11 @@ +package mouda.backend.auth.presentation.response; + +import jakarta.validation.constraints.NotNull; + +public record LegacyOauthRequest( + Long memberId, + + @NotNull + String code +) { +} diff --git a/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java b/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java index bb1999bbd..9cf0a1d05 100644 --- a/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java +++ b/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java @@ -1,5 +1,7 @@ package mouda.backend.member.domain; +import java.util.Objects; + import jakarta.persistence.Embeddable; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -21,4 +23,19 @@ public LoginDetail(OauthType oauthType, String socialLoginId) { this.oauthType = oauthType; this.socialLoginId = socialLoginId; } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + LoginDetail that = (LoginDetail)o; + return oauthType == that.oauthType && Objects.equals(socialLoginId, that.socialLoginId); + } + + @Override + public int hashCode() { + return Objects.hash(oauthType, socialLoginId); + } } diff --git a/backend/src/main/java/mouda/backend/member/implement/MemberWriter.java b/backend/src/main/java/mouda/backend/member/implement/MemberWriter.java index 920514d81..7c736906e 100644 --- a/backend/src/main/java/mouda/backend/member/implement/MemberWriter.java +++ b/backend/src/main/java/mouda/backend/member/implement/MemberWriter.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import mouda.backend.member.domain.Member; +import mouda.backend.member.domain.OauthType; import mouda.backend.member.infrastructure.MemberRepository; @Component @@ -15,4 +16,8 @@ public class MemberWriter { public Member append(Member member) { return memberRepository.save(member); } + + public void updateLoginDetail(long memberId, OauthType oauthType, String socialLoginId) { + memberRepository.updateLoginDetail(memberId, oauthType, socialLoginId); + } } diff --git a/backend/src/main/java/mouda/backend/member/infrastructure/MemberRepository.java b/backend/src/main/java/mouda/backend/member/infrastructure/MemberRepository.java index da27b35df..6e4575cd0 100644 --- a/backend/src/main/java/mouda/backend/member/infrastructure/MemberRepository.java +++ b/backend/src/main/java/mouda/backend/member/infrastructure/MemberRepository.java @@ -3,10 +3,25 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; import mouda.backend.member.domain.Member; +import mouda.backend.member.domain.OauthType; public interface MemberRepository extends JpaRepository { Optional findByLoginDetail_SocialLoginId(String socialLoginId); + + @Transactional + @Query(""" + UPDATE Member m + SET m.loginDetail.oauthType = :oauthType, m.loginDetail.socialLoginId = :socialLoginId + WHERE m.id = :memberId + """) + @Modifying + void updateLoginDetail(@Param("memberId") long memberId, @Param("oauthType") OauthType oauthType, + @Param("socialLoginId") String socialLoginId); } diff --git a/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java b/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java index 003066afe..e0e89bdb6 100644 --- a/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java +++ b/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java @@ -1,14 +1,25 @@ package mouda.backend.auth.business; -import org.assertj.core.api.Assertions; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.Optional; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; 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 mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.implement.AppleOauthManager; +import mouda.backend.auth.presentation.response.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; +import mouda.backend.common.fixture.MemberFixture; +import mouda.backend.member.domain.LoginDetail; +import mouda.backend.member.domain.Member; +import mouda.backend.member.domain.OauthType; +import mouda.backend.member.infrastructure.MemberRepository; @SpringBootTest class AppleAuthServiceTest { @@ -16,15 +27,39 @@ class AppleAuthServiceTest { @Autowired private AppleAuthService appleAuthService; + @MockBean + private AppleOauthManager appleOauthManager; + + @Autowired + private MemberRepository memberRepository; + @DisplayName("애플 로그인 요청을 보내면 access token을 반환한다.") @Test @Disabled("실제 Resource Server에게 요청을 보내는 테스트이다. 프론트 서버를 켜서 코드르 발급 받아 필요할 때만 테스트한다.") void oauthLogin() { String code = ""; - OauthRequest oauthRequest = new OauthRequest(code); + LegacyOauthRequest oauthRequest = new LegacyOauthRequest(1L, code); LoginResponse loginResponse = appleAuthService.oauthLogin(oauthRequest); - Assertions.assertThat(loginResponse).isNotNull(); + assertThat(loginResponse).isNotNull(); + } + + @DisplayName("사용자 전환을 시도하면 새로운 회원을 추가하지 않고 기존 회원의 정보를 수정한다.") + @Test + void oauthLoginConvertingMember() { + String appleSocialLoginId = "appleSocialLoginId"; + when(appleOauthManager.getSocialLoginId(anyString())).thenReturn(appleSocialLoginId); + Member anna = memberRepository.save(MemberFixture.getAnna()); + + Long kakaoMemberId = anna.getId(); + LoginResponse loginResponse = appleAuthService.oauthLogin(new LegacyOauthRequest(kakaoMemberId, "code")); + + assertThat(loginResponse).isNotNull(); + Optional memberOptional = memberRepository.findById(kakaoMemberId); + assertThat(memberOptional.isPresent()).isTrue(); + + LoginDetail expected = new LoginDetail(OauthType.APPLE, appleSocialLoginId); + assertThat(memberOptional.get().getLoginDetail()).isEqualTo(expected); } } From 94b97890f551ea54efd65cfbf5debc2ec5a14897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Fri, 4 Oct 2024 14:03:50 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20access=20token=EA=B3=BC=20=ED=95=A8?= =?UTF-8?q?=EA=BB=98=20member=20id=EB=A5=BC=20=EB=B3=B4=EB=82=B4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/auth/business/AppleAuthService.java | 7 ++++--- .../java/mouda/backend/auth/business/AuthService.java | 2 +- .../backend/auth/business/GoogleAuthService.java | 7 ++++--- .../mouda/backend/auth/business/KakaoAuthService.java | 8 +++++--- .../auth/business/result/LoginProcessResult.java | 7 +++++++ .../mouda/backend/auth/implement/LoginManager.java | 7 ++++--- .../auth/presentation/controller/AuthController.java | 7 ++++--- .../presentation/controller/swagger/AuthSwagger.java | 5 +++-- .../{response => request}/LegacyOauthRequest.java | 4 ++-- .../presentation/response/KakaoLoginResponse.java | 7 +++++++ .../auth/presentation/response/LoginResponse.java | 4 +++- .../backend/auth/business/AppleAuthServiceTest.java | 2 +- .../backend/auth/implement/LoginManagerTest.java | 11 +++++++---- 13 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 backend/src/main/java/mouda/backend/auth/business/result/LoginProcessResult.java rename backend/src/main/java/mouda/backend/auth/presentation/{response => request}/LegacyOauthRequest.java (71%) create mode 100644 backend/src/main/java/mouda/backend/auth/presentation/response/KakaoLoginResponse.java diff --git a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java index 9c0bc6fd9..13cdcd226 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java @@ -3,9 +3,10 @@ import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; +import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.implement.AppleOauthManager; import mouda.backend.auth.implement.LoginManager; -import mouda.backend.auth.presentation.response.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -24,8 +25,8 @@ public LoginResponse oauthLogin(LegacyOauthRequest oauthRequest) { String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.APPLE, socialLoginId); return new LoginResponse(accessToken); } - String accessToken = loginManager.processSocialLogin(OauthType.APPLE, socialLoginId); - return new LoginResponse(accessToken); + LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.APPLE, socialLoginId); + return new LoginResponse(loginProcessResult.accessToken()); } @Override diff --git a/backend/src/main/java/mouda/backend/auth/business/AuthService.java b/backend/src/main/java/mouda/backend/auth/business/AuthService.java index acdcb9546..e3050d279 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AuthService.java @@ -1,6 +1,6 @@ package mouda.backend.auth.business; -import mouda.backend.auth.presentation.response.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; diff --git a/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java index 07d52abe5..fe7fc581a 100644 --- a/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java @@ -3,9 +3,10 @@ import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; +import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.implement.GoogleOauthManager; import mouda.backend.auth.implement.LoginManager; -import mouda.backend.auth.presentation.response.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -25,8 +26,8 @@ public LoginResponse oauthLogin(LegacyOauthRequest oauthRequest) { String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.GOOGLE, socialLoginId); return new LoginResponse(accessToken); } - String accessToken = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); - return new LoginResponse(accessToken); + LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); + return new LoginResponse(loginProcessResult.accessToken()); } @Override diff --git a/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java b/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java index 71286a8d6..72ef1e64d 100644 --- a/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/KakaoAuthService.java @@ -3,10 +3,12 @@ import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; +import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.implement.KakaoOauthManager; import mouda.backend.auth.implement.LoginManager; import mouda.backend.auth.implement.jwt.AccessTokenProvider; import mouda.backend.auth.presentation.request.OauthRequest; +import mouda.backend.auth.presentation.response.KakaoLoginResponse; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.LoginDetail; import mouda.backend.member.domain.Member; @@ -24,11 +26,11 @@ public class KakaoAuthService { private final MemberFinder memberFinder; private final MemberWriter memberWriter; - public LoginResponse oauthLogin(OauthRequest oauthRequest) { + public KakaoLoginResponse oauthLogin(OauthRequest oauthRequest) { String kakaoId = oauthManager.getSocialLoginId(oauthRequest.code()); - String token = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); + LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); - return new LoginResponse(token); + return new KakaoLoginResponse(loginProcessResult.memberId(), loginProcessResult.accessToken()); } public Member findMember(String token) { diff --git a/backend/src/main/java/mouda/backend/auth/business/result/LoginProcessResult.java b/backend/src/main/java/mouda/backend/auth/business/result/LoginProcessResult.java new file mode 100644 index 000000000..28be60be3 --- /dev/null +++ b/backend/src/main/java/mouda/backend/auth/business/result/LoginProcessResult.java @@ -0,0 +1,7 @@ +package mouda.backend.auth.business.result; + +public record LoginProcessResult( + Long memberId, + String accessToken +) { +} diff --git a/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java b/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java index caa6f287e..ab7de02ff 100644 --- a/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java +++ b/backend/src/main/java/mouda/backend/auth/implement/LoginManager.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Component; import lombok.RequiredArgsConstructor; +import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.exception.AuthErrorMessage; import mouda.backend.auth.exception.AuthException; import mouda.backend.auth.implement.jwt.AccessTokenProvider; @@ -25,11 +26,11 @@ public class LoginManager { private final MemberWriter memberWriter; private final MemberFinder memberFinder; - public String processSocialLogin(OauthType oauthType, String socialLoginId) { + public LoginProcessResult processSocialLogin(OauthType oauthType, String socialLoginId) { Optional member = memberRepository.findByLoginDetail_SocialLoginId(socialLoginId); if (member.isPresent()) { - return accessTokenProvider.provide(member.get()); + return new LoginProcessResult(member.get().getId(), accessTokenProvider.provide(member.get())); } if (oauthType == OauthType.KAKAO) { @@ -41,7 +42,7 @@ public String processSocialLogin(OauthType oauthType, String socialLoginId) { .build(); memberWriter.append(newMember); - return accessTokenProvider.provide(newMember); + return new LoginProcessResult(newMember.getId(), accessTokenProvider.provide(newMember)); } public String updateOauth(long memberId, OauthType oauthType, String socialLoginId) { diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java index 5ad746b93..eaeb3ebc9 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java @@ -12,8 +12,9 @@ import mouda.backend.auth.business.GoogleAuthService; import mouda.backend.auth.business.KakaoAuthService; import mouda.backend.auth.presentation.controller.swagger.AuthSwagger; +import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.request.OauthRequest; -import mouda.backend.auth.presentation.response.LegacyOauthRequest; +import mouda.backend.auth.presentation.response.KakaoLoginResponse; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.common.response.RestResponse; @@ -28,8 +29,8 @@ public class AuthController implements AuthSwagger { @Override @PostMapping("/kakao/oauth") - public ResponseEntity> loginKakaoOauth(@RequestBody OauthRequest oauthRequest) { - LoginResponse response = kakaoAuthService.oauthLogin(oauthRequest); + public ResponseEntity> loginKakaoOauth(@RequestBody OauthRequest oauthRequest) { + KakaoLoginResponse response = kakaoAuthService.oauthLogin(oauthRequest); return ResponseEntity.ok().body(new RestResponse<>(response)); } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java index 904f8bc21..3fe570f50 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java @@ -6,8 +6,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.request.OauthRequest; -import mouda.backend.auth.presentation.response.LegacyOauthRequest; +import mouda.backend.auth.presentation.response.KakaoLoginResponse; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.common.response.RestResponse; @@ -17,7 +18,7 @@ public interface AuthSwagger { @ApiResponses({ @ApiResponse(responseCode = "200", description = "로그인 성공!"), }) - ResponseEntity> loginKakaoOauth(@RequestBody OauthRequest oauthRequest); + ResponseEntity> loginKakaoOauth(@RequestBody OauthRequest oauthRequest); @Operation(summary = "테스트 용 로그인", description = "테스트 용 가짜 사용자로 로그인한다(accessToken 발급).") @ApiResponses({ diff --git a/backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java b/backend/src/main/java/mouda/backend/auth/presentation/request/LegacyOauthRequest.java similarity index 71% rename from backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java rename to backend/src/main/java/mouda/backend/auth/presentation/request/LegacyOauthRequest.java index 2e3d4660b..465a53af5 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/response/LegacyOauthRequest.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/request/LegacyOauthRequest.java @@ -1,10 +1,10 @@ -package mouda.backend.auth.presentation.response; +package mouda.backend.auth.presentation.request; import jakarta.validation.constraints.NotNull; public record LegacyOauthRequest( Long memberId, - + @NotNull String code ) { diff --git a/backend/src/main/java/mouda/backend/auth/presentation/response/KakaoLoginResponse.java b/backend/src/main/java/mouda/backend/auth/presentation/response/KakaoLoginResponse.java new file mode 100644 index 000000000..fe19832e7 --- /dev/null +++ b/backend/src/main/java/mouda/backend/auth/presentation/response/KakaoLoginResponse.java @@ -0,0 +1,7 @@ +package mouda.backend.auth.presentation.response; + +public record KakaoLoginResponse( + Long memberId, + String accessToken +) { +} diff --git a/backend/src/main/java/mouda/backend/auth/presentation/response/LoginResponse.java b/backend/src/main/java/mouda/backend/auth/presentation/response/LoginResponse.java index 067496939..78a6f9bae 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/response/LoginResponse.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/response/LoginResponse.java @@ -1,5 +1,7 @@ package mouda.backend.auth.presentation.response; -public record LoginResponse(String accessToken) { +public record LoginResponse( + String accessToken +) { } diff --git a/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java b/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java index e0e89bdb6..8d2242792 100644 --- a/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java +++ b/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java @@ -13,7 +13,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import mouda.backend.auth.implement.AppleOauthManager; -import mouda.backend.auth.presentation.response.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.common.fixture.MemberFixture; import mouda.backend.member.domain.LoginDetail; diff --git a/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java b/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java index b50a0f690..d35a5b546 100644 --- a/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java +++ b/backend/src/test/java/mouda/backend/auth/implement/LoginManagerTest.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.exception.AuthException; import mouda.backend.common.fixture.MemberFixture; import mouda.backend.member.domain.Member; @@ -33,10 +34,12 @@ void processSocialLogin() { memberRepository.save(member); // when - String token = loginManager.processSocialLogin(OauthType.KAKAO, member.getSocialLoginId()); + LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.KAKAO, + member.getSocialLoginId()); // then - assertThat(token).isNotNull(); + assertThat(loginProcessResult.accessToken()).isNotNull(); + assertThat(loginProcessResult.memberId()).isEqualTo(member.getId()); Optional foundMember = memberRepository.findByLoginDetail_SocialLoginId(member.getSocialLoginId()); assertThat(foundMember.isPresent()).isTrue(); assertThat(foundMember.get()).isEqualTo(member); @@ -51,10 +54,10 @@ void processSocialLoginWhoSignedUpBefore() { memberRepository.save(anna); // when - String token = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); + LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); // then - assertThat(token).isNotNull(); + assertThat(loginProcessResult.accessToken()).isNotNull(); } @DisplayName("이전에 카카오로 가입한 적이 없는 사용자가 카카오 로그인을 시도하면 예외를 발생시킨다.") From 656751b80cb38a497687db1620019b4501ee2afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Fri, 4 Oct 2024 15:42:55 +0900 Subject: [PATCH 4/6] Update pr-test.yml --- .github/workflows/pr-test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 4dabf2be5..dc74684bf 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -29,6 +29,11 @@ jobs: mkdir -p src/main/resources/firebase echo ${{ secrets.BACKEND_FIREBASE_JSON }} > src/main/resources/firebase/serviceAccountKey.json + - name: Apple Auth Key 파일 이동 + run: | + mkdir -p src/main/resources/auth + printf "%s" "${{ secrets.APPLE_AUTH_KEY }}" > src/main/resources/auth/AuthKey.p8 + - name: gradlew 권한 부여 run: chmod +x ./gradlew From 58ca7718c74f028244d1508d22f67e42a91d72e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Fri, 4 Oct 2024 16:02:22 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/auth/business/GoogleAuthService.java | 13 +++++++------ .../presentation/controller/AuthController.java | 6 +++--- .../controller/swagger/AuthSwagger.java | 4 ++-- .../presentation/request/GoogleOauthRequest.java | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java index fdc15d874..6a06143c5 100644 --- a/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/GoogleAuthService.java @@ -6,7 +6,7 @@ import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.implement.GoogleOauthManager; import mouda.backend.auth.implement.LoginManager; -import mouda.backend.auth.presentation.request.GoogleOauthReqeust; +import mouda.backend.auth.presentation.request.GoogleOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -18,11 +18,12 @@ public class GoogleAuthService { private final GoogleOauthManager googleOauthManager; private final LoginManager loginManager; - public LoginResponse oauthLogin(GoogleOauthReqeust googleOauthReqeust) { - String memberName = googleOauthManager.getMemberName(googleOauthReqeust.idToken()); - String socialLoginId = googleOauthManager.getSocialLoginId(googleOauthReqeust.idToken()); - if (googleOauthReqeust.memberId() != null) { - String accessToken = loginManager.updateOauth(googleOauthReqeust.memberId(), OauthType.GOOGLE, socialLoginId); + public LoginResponse oauthLogin(GoogleOauthRequest googleOauthRequest) { + String memberName = googleOauthManager.getMemberName(googleOauthRequest.idToken()); + String socialLoginId = googleOauthManager.getSocialLoginId(googleOauthRequest.idToken()); + if (googleOauthRequest.memberId() != null) { + String accessToken = loginManager.updateOauth(googleOauthRequest.memberId(), OauthType.GOOGLE, + socialLoginId); return new LoginResponse(accessToken); } LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java index b2ec7bb36..37b08d8ad 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java @@ -12,7 +12,7 @@ import mouda.backend.auth.business.GoogleAuthService; import mouda.backend.auth.business.KakaoAuthService; import mouda.backend.auth.presentation.controller.swagger.AuthSwagger; -import mouda.backend.auth.presentation.request.GoogleOauthReqeust; +import mouda.backend.auth.presentation.request.GoogleOauthRequest; import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.request.OauthRequest; import mouda.backend.auth.presentation.response.KakaoLoginResponse; @@ -48,8 +48,8 @@ public ResponseEntity> loginBasicOauth() { @Override @PostMapping("/google/oauth") public ResponseEntity> loginGoogleOauth( - @RequestBody GoogleOauthReqeust googleOauthReqeust) { - LoginResponse response = googleAuthService.oauthLogin(googleOauthReqeust); + @RequestBody GoogleOauthRequest googleOauthRequest) { + LoginResponse response = googleAuthService.oauthLogin(googleOauthRequest); return ResponseEntity.ok().body(new RestResponse<>(response)); } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java index fdf061eaa..3316961e9 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java @@ -6,7 +6,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; -import mouda.backend.auth.presentation.request.GoogleOauthReqeust; +import mouda.backend.auth.presentation.request.GoogleOauthRequest; import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.request.OauthRequest; import mouda.backend.auth.presentation.response.KakaoLoginResponse; @@ -37,5 +37,5 @@ public interface AuthSwagger { @ApiResponses({ @ApiResponse(responseCode = "200", description = "로그인 성공!"), }) - ResponseEntity> loginGoogleOauth(@RequestBody GoogleOauthReqeust googleOauthReqeust); + ResponseEntity> loginGoogleOauth(@RequestBody GoogleOauthRequest googleOauthRequest); } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/request/GoogleOauthRequest.java b/backend/src/main/java/mouda/backend/auth/presentation/request/GoogleOauthRequest.java index 1f99ebc22..47745cf90 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/request/GoogleOauthRequest.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/request/GoogleOauthRequest.java @@ -2,7 +2,7 @@ import jakarta.validation.constraints.NotNull; -public record GoogleOauthReqeust( +public record GoogleOauthRequest( Long memberId, @NotNull From acdd8a305999fac8223e94f6adf295b69fb7620c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Fri, 4 Oct 2024 16:34:19 +0900 Subject: [PATCH 6/6] =?UTF-8?q?refactor:=20=EC=95=A0=ED=94=8C=EC=9D=98=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EB=B0=94=EB=94=94=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=9D=84=20AppleOauthRequest=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/mouda/backend/auth/business/AppleAuthService.java | 4 ++-- .../main/java/mouda/backend/auth/business/AuthService.java | 4 ++-- .../auth/presentation/controller/AuthController.java | 4 ++-- .../auth/presentation/controller/swagger/AuthSwagger.java | 4 ++-- .../{LegacyOauthRequest.java => AppleOauthRequest.java} | 2 +- .../mouda/backend/auth/business/AppleAuthServiceTest.java | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) rename backend/src/main/java/mouda/backend/auth/presentation/request/{LegacyOauthRequest.java => AppleOauthRequest.java} (80%) diff --git a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java index 13cdcd226..8ad247eaa 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java @@ -6,7 +6,7 @@ import mouda.backend.auth.business.result.LoginProcessResult; import mouda.backend.auth.implement.AppleOauthManager; import mouda.backend.auth.implement.LoginManager; -import mouda.backend.auth.presentation.request.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.AppleOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; import mouda.backend.member.domain.OauthType; @@ -19,7 +19,7 @@ public class AppleAuthService implements AuthService { private final LoginManager loginManager; @Override - public LoginResponse oauthLogin(LegacyOauthRequest oauthRequest) { + public LoginResponse oauthLogin(AppleOauthRequest oauthRequest) { String socialLoginId = oauthManager.getSocialLoginId(oauthRequest.code()); if (oauthRequest.memberId() != null) { String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.APPLE, socialLoginId); diff --git a/backend/src/main/java/mouda/backend/auth/business/AuthService.java b/backend/src/main/java/mouda/backend/auth/business/AuthService.java index e3050d279..8286e16c2 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AuthService.java @@ -1,12 +1,12 @@ package mouda.backend.auth.business; -import mouda.backend.auth.presentation.request.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.AppleOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.Member; public interface AuthService { - LoginResponse oauthLogin(LegacyOauthRequest oauthRequest); + LoginResponse oauthLogin(AppleOauthRequest oauthRequest); Member findMember(String token); diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java index 37b08d8ad..316ea8a28 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/AuthController.java @@ -12,8 +12,8 @@ import mouda.backend.auth.business.GoogleAuthService; import mouda.backend.auth.business.KakaoAuthService; import mouda.backend.auth.presentation.controller.swagger.AuthSwagger; +import mouda.backend.auth.presentation.request.AppleOauthRequest; import mouda.backend.auth.presentation.request.GoogleOauthRequest; -import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.request.OauthRequest; import mouda.backend.auth.presentation.response.KakaoLoginResponse; import mouda.backend.auth.presentation.response.LoginResponse; @@ -56,7 +56,7 @@ public ResponseEntity> loginGoogleOauth( @Override @PostMapping("/apple/oauth") - public ResponseEntity> loginAppleOauth(@RequestBody LegacyOauthRequest oauthRequest) { + public ResponseEntity> loginAppleOauth(@RequestBody AppleOauthRequest oauthRequest) { LoginResponse response = appleAuthService.oauthLogin(oauthRequest); return ResponseEntity.ok().body(new RestResponse<>(response)); diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java index 3316961e9..644c1865d 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/swagger/AuthSwagger.java @@ -6,8 +6,8 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import mouda.backend.auth.presentation.request.AppleOauthRequest; import mouda.backend.auth.presentation.request.GoogleOauthRequest; -import mouda.backend.auth.presentation.request.LegacyOauthRequest; import mouda.backend.auth.presentation.request.OauthRequest; import mouda.backend.auth.presentation.response.KakaoLoginResponse; import mouda.backend.auth.presentation.response.LoginResponse; @@ -31,7 +31,7 @@ public interface AuthSwagger { @ApiResponses({ @ApiResponse(responseCode = "200", description = "로그인 성공!"), }) - ResponseEntity> loginAppleOauth(@RequestBody LegacyOauthRequest oauthRequest); + ResponseEntity> loginAppleOauth(@RequestBody AppleOauthRequest oauthRequest); @Operation(summary = "구글 oauth 로그인", description = "구글 Oauth Code 를 사용하여 로그인한다(accessToken 발급).") @ApiResponses({ diff --git a/backend/src/main/java/mouda/backend/auth/presentation/request/LegacyOauthRequest.java b/backend/src/main/java/mouda/backend/auth/presentation/request/AppleOauthRequest.java similarity index 80% rename from backend/src/main/java/mouda/backend/auth/presentation/request/LegacyOauthRequest.java rename to backend/src/main/java/mouda/backend/auth/presentation/request/AppleOauthRequest.java index 465a53af5..f6e079728 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/request/LegacyOauthRequest.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/request/AppleOauthRequest.java @@ -2,7 +2,7 @@ import jakarta.validation.constraints.NotNull; -public record LegacyOauthRequest( +public record AppleOauthRequest( Long memberId, @NotNull diff --git a/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java b/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java index 8d2242792..724735aa7 100644 --- a/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java +++ b/backend/src/test/java/mouda/backend/auth/business/AppleAuthServiceTest.java @@ -13,7 +13,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import mouda.backend.auth.implement.AppleOauthManager; -import mouda.backend.auth.presentation.request.LegacyOauthRequest; +import mouda.backend.auth.presentation.request.AppleOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.common.fixture.MemberFixture; import mouda.backend.member.domain.LoginDetail; @@ -38,7 +38,7 @@ class AppleAuthServiceTest { @Disabled("실제 Resource Server에게 요청을 보내는 테스트이다. 프론트 서버를 켜서 코드르 발급 받아 필요할 때만 테스트한다.") void oauthLogin() { String code = ""; - LegacyOauthRequest oauthRequest = new LegacyOauthRequest(1L, code); + AppleOauthRequest oauthRequest = new AppleOauthRequest(1L, code); LoginResponse loginResponse = appleAuthService.oauthLogin(oauthRequest); @@ -53,7 +53,7 @@ void oauthLoginConvertingMember() { Member anna = memberRepository.save(MemberFixture.getAnna()); Long kakaoMemberId = anna.getId(); - LoginResponse loginResponse = appleAuthService.oauthLogin(new LegacyOauthRequest(kakaoMemberId, "code")); + LoginResponse loginResponse = appleAuthService.oauthLogin(new AppleOauthRequest(kakaoMemberId, "code")); assertThat(loginResponse).isNotNull(); Optional memberOptional = memberRepository.findById(kakaoMemberId);