From fb8e9317c2ec2153a6d9ae770aff766df2aefaff Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Wed, 17 Jan 2024 13:52:17 +0900 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20=EB=A9=A4=EB=B2=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C,=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20repository=EB=A1=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/service/Impl/AuthServiceImpl.java | 15 +++------------ .../api/member/repository/MemberRepository.java | 6 ++++++ 2 files changed, 9 insertions(+), 12 deletions(-) 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())); + } }