Skip to content

Commit

Permalink
[REFACTOR] 멤버 조회 시, 예외 처리 로직 repository로 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Jan 17, 2024
1 parent 0777bc2 commit fb8e931
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);

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

0 comments on commit fb8e931

Please sign in to comment.