Skip to content

Commit

Permalink
[refac] change package
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Jan 13, 2025
1 parent d49152a commit f83fae9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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> user = userFinder.findUserByPlatFormAndSeralId(platform, socialInfo.serialId());
boolean isRegistered = isRegistered(user);
User findUser = loadOrCreateUser(user, platform, socialInfo);
Expand All @@ -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();
}
Expand Down Expand Up @@ -90,30 +89,30 @@ private boolean isRegistered(final Optional<User> 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<User> findUser, final Platform platform, final SocialInfoDto socialInfo) {
private User loadOrCreateUser(final Optional<User> 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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

This file was deleted.

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

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

0 comments on commit f83fae9

Please sign in to comment.