From cdf57abc13f78d751b442826f56aee319827e53b Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 07:28:07 +0900 Subject: [PATCH] =?UTF-8?q?[Weekly/11/Refactor/TokenResponse]=20token=20re?= =?UTF-8?q?sponse=EC=97=90=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94,=20=ED=83=80=EC=9E=85=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B0=98=EC=98=81=20(#139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_develop/api/TempCreateController.java | 3 ++- .../auth/api/dto/SocialTokenResponse.java | 3 ++- .../wouldyouin/auth/api/dto/TokenResponse.java | 7 +++++-- .../wouldyouin/auth/application/AuthService.java | 15 ++++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java index ef6b0557..4b0dc57b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java @@ -75,6 +75,7 @@ public ResponseEntity> testCreateToken( } private TokenResponse createToken(MemberIdentifier identifier) { - return TokenResponse.from(jwtService.createAccessToken(identifier.id(), identifier.type())); + String accessToken = jwtService.createAccessToken(identifier.id(), identifier.type()); + return TokenResponse.of(accessToken, identifier.id(), identifier.type()); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java index bfdb4f43..ad4af168 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java @@ -1,8 +1,9 @@ package org.ktc2.cokaen.wouldyouin.auth.api.dto; import lombok.Builder; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Builder -public record SocialTokenResponse(Boolean isWelcomeMember, String token) { +public record SocialTokenResponse(Boolean isWelcomeMember, String token, Long memberId, MemberType memberType) { } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java index 0ebae147..c40ba589 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java @@ -1,13 +1,16 @@ package org.ktc2.cokaen.wouldyouin.auth.api.dto; import lombok.Builder; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Builder -public record TokenResponse(String token) { +public record TokenResponse(String token, Long memberId, MemberType memberType) { - public static TokenResponse from(String token) { + public static TokenResponse of(String token, Long memberId, MemberType memberType) { return TokenResponse.builder() .token(token) + .memberId(memberId) + .memberType(memberType) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java index 39631274..817e4b65 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java @@ -33,12 +33,14 @@ public class AuthService { @Transactional public TokenResponse localSignup(LocalSignupRequest request) { baseMemberService.checkUniqueEmailOrThrow(request.getEmail()); - return TokenResponse.from(createToken(hostService.createHost(request))); + MemberResponse response = hostService.createHost(request); + return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType()); } @Transactional(readOnly = true) public TokenResponse localLogin(LocalLoginRequest request) { - return TokenResponse.from(createToken(hostService.getMemberResponseBy(request))); + MemberResponse response = hostService.getMemberResponseBy(request); + return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType()); } @Transactional @@ -55,6 +57,8 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) { return SocialTokenResponse.builder() .isWelcomeMember(false) .token(createToken(id)) + .memberId(id.id()) + .memberType(id.type()) .build(); } // 소셜 계정이지만 아직 추가 정보 기입이 되지 않은 경우 @@ -62,6 +66,8 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) { return SocialTokenResponse.builder() .isWelcomeMember(true) .token(createToken(id)) + .memberId(id.id()) + .memberType(id.type()) .build(); } } @@ -78,12 +84,15 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) { return SocialTokenResponse.builder() .isWelcomeMember(true) .token(createToken(welcomeMemberResponse)) + .memberId(welcomeMemberResponse.getMemberId()) + .memberType(welcomeMemberResponse.getMemberType()) .build(); } @Transactional public TokenResponse acceptAdditionalInfo(Long welcomeMemberId, MemberAdditionalInfoRequest request) { - return TokenResponse.from(createToken(memberService.updateWelcomeMember(welcomeMemberId, request))); + MemberResponse response = memberService.updateWelcomeMember(welcomeMemberId, request); + return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType()); } private String createToken(MemberIdentifier identifier) {