Skip to content

Commit

Permalink
refactor: 구글 이름 반환 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyeonyy committed Oct 11, 2024
1 parent 7ebd866 commit 5096365
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ public LoginResponse oauthLogin(GoogleOauthRequest googleOauthRequest) {
String name = 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);
return transferKakao(googleOauthRequest, socialLoginId);
}
return processGoogleLogin(socialLoginId, name);
}

private LoginResponse transferKakao(GoogleOauthRequest googleOauthRequest, String socialLoginId) {
String accessToken = loginManager.updateOauth(googleOauthRequest.memberId(), OauthType.GOOGLE,
socialLoginId);
return new LoginResponse(accessToken);
}

private LoginResponse processGoogleLogin(String socialLoginId, String name) {
LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId, name);
return new LoginResponse(loginProcessResult.accessToken());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public class LoginManager {
public LoginProcessResult processSocialLogin(OauthType oauthType, String socialLoginId, String name) {
Optional<Member> member = memberRepository.findByLoginDetail_SocialLoginId(socialLoginId);

if (member.isPresent()) {
return new LoginProcessResult(member.get().getId(), accessTokenProvider.provide(member.get()));
}
return member.map(value -> {
memberWriter.updateName(value.getId(), name);
return new LoginProcessResult(value.getId(), accessTokenProvider.provide(value));
})
.orElseGet(() -> processKakaoLogin(oauthType, socialLoginId, name));

}

private LoginProcessResult processKakaoLogin(OauthType oauthType, String socialLoginId, String name) {
if (oauthType == OauthType.KAKAO) {
throw new AuthException(HttpStatus.BAD_REQUEST, AuthErrorMessage.KAKAO_CANNOT_SIGNUP);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public void updateLoginDetail(long memberId, OauthType oauthType, String socialL
memberRepository.updateLoginDetail(memberId, oauthType, socialLoginId);
}

public void updateName(long memberId, String name) {
memberRepository.updateName(memberId, name);
}

public void remove(Member member) {
memberRepository.delete(member);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
Expand All @@ -15,13 +14,20 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

Optional<Member> findByLoginDetail_SocialLoginId(String socialLoginId);

@Transactional
@Query("""
UPDATE Member m
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);

@Query("""
UPDATE Member m
SET m.name = :name
WHERE m.id = :memberId
""")
@Modifying
void updateName(@Param("memberId") long memberId, @Param("name") String name);
}

0 comments on commit 5096365

Please sign in to comment.