diff --git a/src/main/java/com/example/daemawiki/domain/mail/api/MailController.java b/src/main/java/com/example/daemawiki/domain/mail/api/MailController.java index da25d69f..d560deb6 100644 --- a/src/main/java/com/example/daemawiki/domain/mail/api/MailController.java +++ b/src/main/java/com/example/daemawiki/domain/mail/api/MailController.java @@ -2,6 +2,7 @@ import com.example.daemawiki.domain.mail.dto.AuthCodeRequest; import com.example.daemawiki.domain.mail.dto.AuthCodeVerifyRequest; +import com.example.daemawiki.domain.mail.dto.AuthCodeVerifyResponse; import com.example.daemawiki.domain.mail.service.MailSend; import com.example.daemawiki.domain.mail.service.MailVerify; import org.springframework.web.bind.annotation.PostMapping; @@ -27,7 +28,7 @@ public Mono send(@RequestBody AuthCodeRequest request) { } @PostMapping("/verify") - public Mono verify(@RequestBody AuthCodeVerifyRequest request) { + public Mono verify(@RequestBody AuthCodeVerifyRequest request) { return mailVerify.execute(request); } diff --git a/src/main/java/com/example/daemawiki/domain/mail/service/MailVerify.java b/src/main/java/com/example/daemawiki/domain/mail/service/MailVerify.java index 074a7ea5..34e882af 100644 --- a/src/main/java/com/example/daemawiki/domain/mail/service/MailVerify.java +++ b/src/main/java/com/example/daemawiki/domain/mail/service/MailVerify.java @@ -1,6 +1,7 @@ package com.example.daemawiki.domain.mail.service; import com.example.daemawiki.domain.mail.dto.AuthCodeVerifyRequest; +import com.example.daemawiki.domain.mail.dto.AuthCodeVerifyResponse; import com.example.daemawiki.domain.mail.model.AuthCode; import com.example.daemawiki.domain.mail.model.AuthMail; import com.example.daemawiki.domain.mail.repository.AuthCodeRepository; @@ -18,14 +19,26 @@ public MailVerify(AuthMailRepository authMailRepository, AuthCodeRepository auth this.codeRepository = authCodeRepository; } - public Mono execute(AuthCodeVerifyRequest request) { + public Mono execute(AuthCodeVerifyRequest request) { String mail = request.mail(); return getAuthCode(mail, request.authCode()) .flatMap(authCode -> save(mail) .then(codeRepository.delete(authCode)) - .thenReturn(true)) - .switchIfEmpty(Mono.defer(() -> Mono.just(false))); + .thenReturn(getResponse(true))) + .switchIfEmpty(Mono.defer(() -> Mono.just(getResponse(false)))); + } + + private static final String SUCCESS = "인증에 성공했습니다."; + private static final String FAIL = "인증에 실패했습니다."; + + private AuthCodeVerifyResponse getResponse(Boolean bool) { + String message = bool ? SUCCESS : FAIL; + + return AuthCodeVerifyResponse.builder() + .isSuccess(bool) + .message(message) + .build(); } private Mono save(String mail) {