Skip to content

Commit

Permalink
♻️ :: (#12) update exception standard to custom
Browse files Browse the repository at this point in the history
  • Loading branch information
iqpizza6349 committed Feb 22, 2023
1 parent fdf0446 commit c4782e9
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.NoSuchElementException;
import java.time.ZoneId;

@UseCase
@RequiredArgsConstructor
public class UserRecoveryUseCase implements UserRecoveryApi {

// TODO: 2023-02-16 UserRecoveryApi 가 SRP 를 위배하는 상태임
// 하지만 이메일 인증은 회원 리커버리 파트 중 하나이기에 어찌보면 SRP 를 제대로 지킨 것일 수 도 있음

private final QueryUserSpi queryUserSpi;
private final EmailCertificationSpi emailCertificationSpi;
private final RandomCodeSpi<Object> randomCodeSpi;
Expand All @@ -48,11 +45,11 @@ public void resetPassword(MemberRecoveryPasswordVO memberRecoveryPasswordVO) {
final String code = memberRecoveryPasswordVO.getVerificationCode();

if (!emailCertificationSpi.matches(code)) {
throw new IllegalStateException("인증코드와 일치하지 않습니다.");
throw new Member.CertificationCodeMismatchException();
}

Member member = queryUserSpi.findUserByEmail(email)
.orElseThrow(() -> new NoSuchElementException("존재하지 않는 회원입니다."));
.orElseThrow(Member.MemberNotFoundException::new);
member.setPassword(password);
queryUserSpi.saveUser(member);
}
Expand All @@ -66,6 +63,7 @@ public void sendVerificationCode(String email) {

protected LocalDate stringToLocalDate(String data) throws ParseException {
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
return LocalDate.from(dateFormat.parse(data).toInstant());
return LocalDate.from(dateFormat.parse(data).toInstant()
.atZone(ZoneId.of("Asia/Seoul")).toLocalDate());
}
}

0 comments on commit c4782e9

Please sign in to comment.