diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/member/auth/service/Impl/AuthServiceImpl.java b/growthookServer/src/main/java/com/example/growthookserver/api/member/auth/service/Impl/AuthServiceImpl.java index 62f1fdf..8c2afc5 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/member/auth/service/Impl/AuthServiceImpl.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/member/auth/service/Impl/AuthServiceImpl.java @@ -45,7 +45,7 @@ public AuthResponseDto socialLogin(AuthRequestDto authRequestDto) throws NoSuchA String refreshToken = jwtTokenProvider.generateRefreshToken(); - Boolean isExistUser = isMemberBySocialId(socialData.getId()); + Boolean isExistUser = memberRepository.existsBySocialId(socialData.getId()); // 신규 유저 저장 if (!isExistUser.booleanValue()) { @@ -61,10 +61,10 @@ public AuthResponseDto socialLogin(AuthRequestDto authRequestDto) throws NoSuchA member.updateRefreshToken(refreshToken); } - else findMemberBySocialId(socialData.getId()).updateRefreshToken(refreshToken); + else memberRepository.findMemberBySocialIdOrThrow(socialData.getId()).updateRefreshToken(refreshToken); // socialId를 통해서 등록된 유저 찾기 - Member signedMember = findMemberBySocialId(socialData.getId()); + Member signedMember = memberRepository.findMemberBySocialIdOrThrow(socialData.getId()); Authentication authentication = new UserAuthentication(signedMember.getId(), null, null); @@ -83,15 +83,6 @@ public AuthTokenResponseDto getNewToken(String accessToken, String refreshToken) return AuthTokenResponseDto.of(accessToken,refreshToken); } - private Member findMemberBySocialId(String socialId) { - return memberRepository.findBySocialId(socialId) - .orElseThrow(() -> new BadRequestException(ErrorStatus.INVALID_MEMBER.getMessage())); - } - - private boolean isMemberBySocialId(String socialId) { - return memberRepository.existsBySocialId(socialId); - } - private SocialInfoDto getSocialData(SocialPlatform socialPlatform, String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { switch (socialPlatform) { diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/member/repository/MemberRepository.java b/growthookServer/src/main/java/com/example/growthookserver/api/member/repository/MemberRepository.java index 43617d1..8c63c37 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/member/repository/MemberRepository.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/member/repository/MemberRepository.java @@ -1,6 +1,7 @@ package com.example.growthookserver.api.member.repository; import com.example.growthookserver.api.member.domain.Member; +import com.example.growthookserver.common.exception.BadRequestException; import com.example.growthookserver.common.exception.NotFoundException; import com.example.growthookserver.common.response.ErrorStatus; import org.springframework.data.jpa.repository.JpaRepository; @@ -19,4 +20,9 @@ default Member findMemberByIdOrThrow(Long memberId){ return findMemberById(memberId) .orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_MEMBER.getMessage())); } + + default Member findMemberBySocialIdOrThrow(String socialId) { + return findBySocialId(socialId) + .orElseThrow(() -> new BadRequestException(ErrorStatus.INVALID_MEMBER.getMessage())); + } }