From f83fae97aa338c3b8dda2e7a6592eda46660a459 Mon Sep 17 00:00:00 2001 From: kgy1008 Date: Mon, 13 Jan 2025 13:55:44 +0900 Subject: [PATCH] [refac] change package --- .../api/auth/service/AuthService.java | 17 ++++++++--------- .../api/auth/service/OAuthProvider.java | 10 ++++++++++ .../api/auth/service/OAuthProviderFactory.java | 1 - .../hankkiserver/domain/user/model/User.java | 4 ++-- .../external/openfeign/oauth/OAuthProvider.java | 8 -------- ...cialInfoDto.java => SocialInfoResponse.java} | 6 +++--- .../oauth/apple/AppleOAuthProvider.java | 8 ++++---- .../oauth/kakao/KakaoOAuthProvider.java | 8 ++++---- 8 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProvider.java delete mode 100644 src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/OAuthProvider.java rename src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/{SocialInfoDto.java => SocialInfoResponse.java} (58%) diff --git a/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java b/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java index 068a2f07..c57bf1c7 100644 --- a/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java +++ b/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java @@ -19,8 +19,7 @@ import org.hankki.hankkiserver.domain.user.model.UserStatus; import org.hankki.hankkiserver.event.EventPublisher; import org.hankki.hankkiserver.event.user.CreateUserEvent; -import org.hankki.hankkiserver.external.openfeign.oauth.OAuthProvider; -import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoDto; +import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +39,7 @@ public class AuthService { @Transactional public UserLoginResponse login(final String token, final UserLoginRequest request) { Platform platform = Platform.getEnumPlatformFromStringPlatform(request.platform()); - SocialInfoDto socialInfo = getSocialInfo(token, platform, request.name()); + SocialInfoResponse socialInfo = getSocialInfo(token, platform, request.name()); Optional user = userFinder.findUserByPlatFormAndSeralId(platform, socialInfo.serialId()); boolean isRegistered = isRegistered(user); User findUser = loadOrCreateUser(user, platform, socialInfo); @@ -59,7 +58,7 @@ public void withdraw(final long userId, final String code) { User user = userFinder.getUser(userId); Platform platform = user.getPlatform(); OAuthProvider oAuthProvider = oAuthProviderFactory.findProvider(platform); - oAuthProvider.requestRevoke(code, user.getSerialId()); // code는 apple이 필요, serialId는 카카오가 필요 + oAuthProvider.requestRevoke(code, user.getSerialId()); user.softDelete(); userInfoFinder.getUserInfo(userId).softDelete(); } @@ -90,30 +89,30 @@ private boolean isRegistered(final Optional user) { .orElse(false); } - private SocialInfoDto getSocialInfo(final String providerToken, final Platform platform, final String name) { + private SocialInfoResponse getSocialInfo(final String providerToken, final Platform platform, final String name) { OAuthProvider oAuthProvider = oAuthProviderFactory.findProvider(platform); return oAuthProvider.getUserInfo(providerToken, name); } - private User loadOrCreateUser(final Optional findUser, final Platform platform, final SocialInfoDto socialInfo) { + private User loadOrCreateUser(final Optional findUser, final Platform platform, final SocialInfoResponse socialInfo) { return findUser.map(user -> updateOrGetUserInfo(user, user.getStatus(), socialInfo)) .orElseGet(() -> createNewUser(socialInfo, platform)); } - private User updateOrGetUserInfo(final User user, final UserStatus status, final SocialInfoDto socialInfo) { + private User updateOrGetUserInfo(final User user, final UserStatus status, final SocialInfoResponse socialInfo) { if (status == ACTIVE) { return user; } return updateUserInfo(user, socialInfo); } - private User updateUserInfo(final User user, final SocialInfoDto socialInfo) { + private User updateUserInfo(final User user, final SocialInfoResponse socialInfo) { user.rejoin(socialInfo); userInfoFinder.getUserInfo(user.getId()).updateNickname(socialInfo.name()); return user; } - private User createNewUser(final SocialInfoDto socialInfo, final Platform platform) { + private User createNewUser(final SocialInfoResponse socialInfo, final Platform platform) { User newUser = createUser(socialInfo.name(), socialInfo.email(), socialInfo.serialId(), platform); saveUserAndUserInfo(newUser); eventPublisher.publish(CreateUserEvent.of(newUser.getId(), newUser.getName(), newUser.getPlatform().toString())); diff --git a/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProvider.java b/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProvider.java new file mode 100644 index 00000000..2dc44512 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProvider.java @@ -0,0 +1,10 @@ +package org.hankki.hankkiserver.api.auth.service; + +import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; + +public interface OAuthProvider { + + SocialInfoResponse getUserInfo(String token, String name); + + void requestRevoke(String code, String Id); +} diff --git a/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProviderFactory.java b/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProviderFactory.java index 959d186e..75e6a1b0 100644 --- a/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProviderFactory.java +++ b/src/main/java/org/hankki/hankkiserver/api/auth/service/OAuthProviderFactory.java @@ -3,7 +3,6 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import org.hankki.hankkiserver.domain.user.model.Platform; -import org.hankki.hankkiserver.external.openfeign.oauth.OAuthProvider; import org.springframework.stereotype.Component; @Component diff --git a/src/main/java/org/hankki/hankkiserver/domain/user/model/User.java b/src/main/java/org/hankki/hankkiserver/domain/user/model/User.java index efd035a7..4461cf54 100644 --- a/src/main/java/org/hankki/hankkiserver/domain/user/model/User.java +++ b/src/main/java/org/hankki/hankkiserver/domain/user/model/User.java @@ -4,7 +4,7 @@ import lombok.*; import org.hankki.hankkiserver.domain.common.BaseTimeEntity; -import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoDto; +import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; import java.time.LocalDateTime; @@ -66,7 +66,7 @@ public void softDelete() { this.email = "알 수 없음"; } - public void rejoin(final SocialInfoDto socialInfo) { + public void rejoin(final SocialInfoResponse socialInfo) { updateStatus(ACTIVE); updateDeletedAt(null); this.name = socialInfo.name(); diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/OAuthProvider.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/OAuthProvider.java deleted file mode 100644 index 5139e7a8..00000000 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/OAuthProvider.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.hankki.hankkiserver.external.openfeign.oauth; - -public interface OAuthProvider { - - SocialInfoDto getUserInfo(String token, String name); - - void requestRevoke(String code, String Id); -} diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/SocialInfoDto.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/SocialInfoResponse.java similarity index 58% rename from src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/SocialInfoDto.java rename to src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/SocialInfoResponse.java index f22ebc2a..cc885dee 100644 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/SocialInfoDto.java +++ b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/SocialInfoResponse.java @@ -1,16 +1,16 @@ package org.hankki.hankkiserver.external.openfeign.oauth; -public record SocialInfoDto( +public record SocialInfoResponse( String serialId, String name, String email) { private static final String DEFAULT_NAME = "한끼"; - public static SocialInfoDto of(final String serialId, String name, final String email) { + public static SocialInfoResponse of(final String serialId, String name, final String email) { if (name.isBlank()) { name = DEFAULT_NAME; } - return new SocialInfoDto(serialId, name, email); + return new SocialInfoResponse(serialId, name, email); } } diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/apple/AppleOAuthProvider.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/apple/AppleOAuthProvider.java index 76f3ae0f..ccc7a668 100644 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/apple/AppleOAuthProvider.java +++ b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/apple/AppleOAuthProvider.java @@ -6,10 +6,10 @@ import lombok.RequiredArgsConstructor; import org.hankki.hankkiserver.common.code.AuthErrorCode; import org.hankki.hankkiserver.common.exception.BadRequestException; -import org.hankki.hankkiserver.external.openfeign.oauth.OAuthProvider; +import org.hankki.hankkiserver.api.auth.service.OAuthProvider; import org.hankki.hankkiserver.external.openfeign.oauth.apple.dto.ApplePublicKeys; import org.hankki.hankkiserver.external.openfeign.oauth.apple.dto.AppleTokenResponse; -import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoDto; +import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -29,12 +29,12 @@ public class AppleOAuthProvider implements OAuthProvider { private static final String GRANT_TYPE = "authorization_code"; @Override - public SocialInfoDto getUserInfo(final String identityToken, final String name) { + public SocialInfoResponse getUserInfo(final String identityToken, final String name) { Map headers = appleIdentityTokenParser.parseHeaders(identityToken); ApplePublicKeys applePublicKeys = appleFeignClient.getApplePublicKey(); PublicKey applePublicKey = applePublicKeyGenerator.generatePublicKey(headers, applePublicKeys); Claims claims = appleIdentityTokenParser.parsePublicKeyAndGetClaims(identityToken, applePublicKey); - return SocialInfoDto.of( + return SocialInfoResponse.of( claims.get("sub").toString(), name, claims.get("email").toString()); diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/kakao/KakaoOAuthProvider.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/kakao/KakaoOAuthProvider.java index 58df53aa..57611352 100644 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/kakao/KakaoOAuthProvider.java +++ b/src/main/java/org/hankki/hankkiserver/external/openfeign/oauth/kakao/KakaoOAuthProvider.java @@ -3,8 +3,8 @@ import static org.hankki.hankkiserver.external.openfeign.oauth.kakao.KakaoAccessToken.createKakaoAccessToken; import lombok.RequiredArgsConstructor; -import org.hankki.hankkiserver.external.openfeign.oauth.OAuthProvider; -import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoDto; +import org.hankki.hankkiserver.api.auth.service.OAuthProvider; +import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; import org.hankki.hankkiserver.external.openfeign.oauth.kakao.dto.KakaoUserInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -20,11 +20,11 @@ public class KakaoOAuthProvider implements OAuthProvider { private static final String TARGET_ID_TYPE = "user_id"; @Override - public SocialInfoDto getUserInfo(final String providerToken, final String name) { + public SocialInfoResponse getUserInfo(final String providerToken, final String name) { KakaoAccessToken kakaoAccessToken = createKakaoAccessToken(providerToken); String accessTokenWithTokenType = kakaoAccessToken.getAccessTokenWithTokenType(); KakaoUserInfo kakaoUserInfo = kakaoFeignClient.getUserInfo(accessTokenWithTokenType); - return SocialInfoDto.of( + return SocialInfoResponse.of( kakaoUserInfo.id().toString(), kakaoUserInfo.kakaoAccount().kakaoUserProfile().nickname(), kakaoUserInfo.kakaoAccount().email());