Skip to content

Commit

Permalink
fix: 일반 회원이 아닌 휴대폰 번호 조회 시 not-found 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlee1703 committed Apr 17, 2024
1 parent fdf77cd commit 2aa5e6b
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package kr.co.pennyway.api.apis.auth.mapper;

import org.springframework.transaction.annotation.Transactional;

import kr.co.pennyway.api.apis.auth.dto.AuthFindDto;
import kr.co.pennyway.api.common.exception.AuthFindErrorCode;
import kr.co.pennyway.api.common.exception.AuthFinderException;
import kr.co.pennyway.common.annotation.Mapper;
import kr.co.pennyway.domain.domains.user.domain.User;
import kr.co.pennyway.domain.domains.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -12,10 +17,18 @@
public class AuthFindMapper {
private final UserService userService;

@Transactional(readOnly = true)
public AuthFindDto.FindUsernameRes findUsername(String phone) {
return AuthFindDto.FindUsernameRes.of(userService.readUserByPhone(phone).orElseThrow(() -> {
User user = userService.readUserByPhone(phone).orElseThrow(() -> {
log.error("User not found by phone: {}", phone);
return new AuthFinderException(AuthFindErrorCode.EXPIRED_OR_INVALID_PHONE);
});

if (user.getPassword() == null) {
log.error("User not found by phone: {}", phone);
return new RuntimeException("User not found by phone: " + phone);
}));
throw new AuthFinderException(AuthFindErrorCode.EXPIRED_OR_INVALID_PHONE);
}

return AuthFindDto.FindUsernameRes.of(user);
}
}

0 comments on commit 2aa5e6b

Please sign in to comment.