From 6d5e2ce2a1d278d31303de4040e6ca5a6193a4c6 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 15 Sep 2024 00:54:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[style]=20=EA=B3=B5=EB=B0=B1=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/service/AuthService.java | 10 ++-------- .../domain/auth/util/social/GoogleLogin.java | 2 -- .../domain/auth/util/social/KakaoLogin.java | 2 -- .../domain/auth/util/social/SocialLogin.java | 12 ------------ 4 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/service/AuthService.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/service/AuthService.java index 3bf42ff5..6996d7e7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/service/AuthService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/service/AuthService.java @@ -40,17 +40,11 @@ public class AuthService { @Transactional public BaseResponseDto googleLogin(String googleAccessToken) { - - return BaseResponseDto.of(SuccessCode.SUCCESS, - googleLogin.loginMethod(googleAccessToken)); + return BaseResponseDto.of(SuccessCode.SUCCESS, googleLogin.loginMethod(googleAccessToken)); } @Transactional public BaseResponseDto kakaoLogin(String kakaoAccessToken) { - - return BaseResponseDto.of(SuccessCode.SUCCESS, - kakaoLogin.loginMethod(kakaoAccessToken)); - - + return BaseResponseDto.of(SuccessCode.SUCCESS, kakaoLogin.loginMethod(kakaoAccessToken)); } @Transactional public BaseResponseDto logout(Long userId) { diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java index fe63856e..da6c1271 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java @@ -22,8 +22,6 @@ public LoginResponseDto loginMethod(String socialToken) { socialToken, "https://www.googleapis.com/oauth2/v2/userinfo", GoogleUserResponseDto.class); - - return login(socialUserData); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java index 2ddb3335..192d8c23 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java @@ -23,8 +23,6 @@ public LoginResponseDto loginMethod(String socialToken) { socialToken, "https://kapi.kakao.com/v2/user/me", KakaoUserResponseDto.class); - - return login(socialUserData); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java index 80c99f49..bbe018b0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java @@ -35,23 +35,17 @@ abstract public class SocialLogin { public LoginResponseDto login(SocialUserResponseDto socialUserData){ verifySocialUserData(socialUserData); - userRepository.findByUserNumber(String.valueOf(socialUserData.getId())) .orElseGet(() -> { - socialSignUp(socialUserData); return null; }); - Optional userLoginData = Optional.ofNullable(userRepository.findByUserNumber(String.valueOf(socialUserData.getId())).orElseThrow(() -> new UserNotFoundException("해당 유저의 정보가 존재하지 않습니다.", UserErrorCode.NOT_FOUND_USER))); - String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); String accessToken = jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole())); - redisManager.setValueByKey(String.valueOf(userLoginData.get().getId()), refreshToken); - return LoginResponseDto.of( accessToken, refreshToken, @@ -60,33 +54,27 @@ public LoginResponseDto login(SocialUserResponseDto socialUserData){ } private void verifySocialUserData(T data){ - if(data == null){ - BaseResponseDto.of(UserErrorCode.NOT_FOUND_USER, "요청한 소셜 유저 정보가 없습니다."); } } private void socialSignUp(T socialUserData) { - User user = User.createUser( "USER", String.valueOf(socialUserData.getId()), true ); userRepository.save(user); - } public T getUserData(String accessToken, String apiUrl, Class responseType){ - Mono userInfoMono = webClient .get() .uri(apiUrl) .headers(headers -> headers.set("Authorization", accessToken)) .retrieve() .bodyToMono(responseType); - return userInfoMono.block(); } From 70ad5bb7ab37b0a86b29de2a6e29d41112532731 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 15 Sep 2024 01:02:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=EA=B3=B5=EB=B0=B1=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/auth/util/social/GoogleLogin.java | 5 +++-- .../farmusspring/domain/auth/util/social/KakaoLogin.java | 5 +++-- .../farmusspring/domain/auth/util/social/SocialLogin.java | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java index da6c1271..c1274dfe 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/GoogleLogin.java @@ -3,6 +3,7 @@ import com.modernfarmer.farmusspring.domain.auth.dto.LoginResponseDto; import com.modernfarmer.farmusspring.domain.auth.repository.RedisManager; import com.modernfarmer.farmusspring.domain.auth.util.social.dto.GoogleUserResponseDto; +import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import com.modernfarmer.farmusspring.global.common.security.JwtTokenProvider; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -12,8 +13,8 @@ @Component public class GoogleLogin extends SocialLogin{ - public GoogleLogin(WebClient webClient, JwtTokenProvider jwtTokenProvider, RedisManager redisManager, UserRepository userRepository) { - super(webClient, jwtTokenProvider, redisManager, userRepository); + public GoogleLogin(WebClient webClient, JwtTokenProvider jwtTokenProvider, RedisManager redisManager, UserRepository userRepository, HistoryHelper historyHelper) { + super(webClient, jwtTokenProvider, redisManager, userRepository, historyHelper); } @Override diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java index 192d8c23..13925deb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/KakaoLogin.java @@ -4,6 +4,7 @@ import com.modernfarmer.farmusspring.domain.auth.dto.LoginResponseDto; import com.modernfarmer.farmusspring.domain.auth.repository.RedisManager; import com.modernfarmer.farmusspring.domain.auth.util.social.dto.KakaoUserResponseDto; +import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import com.modernfarmer.farmusspring.global.common.security.JwtTokenProvider; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -13,8 +14,8 @@ @Component public class KakaoLogin extends SocialLogin { - public KakaoLogin(WebClient webClient, JwtTokenProvider jwtTokenProvider, RedisManager redisManager, UserRepository userRepository) { - super(webClient, jwtTokenProvider, redisManager, userRepository); + public KakaoLogin(WebClient webClient, JwtTokenProvider jwtTokenProvider, RedisManager redisManager, UserRepository userRepository, HistoryHelper historyHelper) { + super(webClient, jwtTokenProvider, redisManager, userRepository, historyHelper); } @Override diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java index bbe018b0..1bac2e03 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java @@ -3,6 +3,7 @@ import com.modernfarmer.farmusspring.domain.auth.dto.LoginResponseDto; import com.modernfarmer.farmusspring.domain.auth.repository.RedisManager; import com.modernfarmer.farmusspring.domain.auth.util.social.dto.SocialUserResponseDto; +import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.domain.user.exception.custom.UserNotFoundException; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; @@ -28,6 +29,7 @@ abstract public class SocialLogin { private final JwtTokenProvider jwtTokenProvider; private final RedisManager redisManager; private final UserRepository userRepository; + private final HistoryHelper historyHelper; public abstract LoginResponseDto loginMethod(String socialToken); @@ -42,10 +44,9 @@ public LoginResponseDto login(SocialUserResponseDto socialUserData){ }); Optional userLoginData = Optional.ofNullable(userRepository.findByUserNumber(String.valueOf(socialUserData.getId())).orElseThrow(() -> new UserNotFoundException("해당 유저의 정보가 존재하지 않습니다.", UserErrorCode.NOT_FOUND_USER))); String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); - String accessToken = jwtTokenProvider.createAccessToken( - userLoginData.get().getId(), - String.valueOf(userLoginData.get().getRole())); + String accessToken = jwtTokenProvider.createAccessToken(userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole())); redisManager.setValueByKey(String.valueOf(userLoginData.get().getId()), refreshToken); + historyHelper.createUserHistory(userLoginData.get().getId()); return LoginResponseDto.of( accessToken, refreshToken,