Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
메일 인증 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Jan 24, 2024
1 parent c82c3e7 commit b9269d5
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.daemawiki.domain.mail.service;

import com.example.daemawiki.domain.mail.dto.AuthCodeVerifyRequest;
import com.example.daemawiki.domain.mail.model.AuthCode;
import com.example.daemawiki.domain.mail.model.AuthMail;
import com.example.daemawiki.domain.mail.repository.AuthCodeRepository;
import com.example.daemawiki.domain.mail.repository.AuthMailRepository;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
public class MailVerify {
private final AuthMailRepository mailRepository;
private final AuthCodeRepository codeRepository;

public MailVerify(AuthMailRepository authMailRepository, AuthCodeRepository authCodeRepository) {
this.mailRepository = authMailRepository;
this.codeRepository = authCodeRepository;
}

public Mono<Boolean> verify(AuthCodeVerifyRequest request) {
return getAuthCode(request.mail(), request.authCode())
.flatMap(authCode -> mailRepository.save(AuthMail.builder()
.mail(request.mail())
.build())
.then(codeRepository.delete(authCode))
.thenReturn(true))
.switchIfEmpty(Mono.just(false));
}

private Mono<AuthCode> getAuthCode(String mail, String authCode) {
return codeRepository.findByMailAndCode(mail, authCode);
}

}

0 comments on commit b9269d5

Please sign in to comment.