From 7a59f8558dba100fb1d69ae4689d6bb36597e5a8 Mon Sep 17 00:00:00 2001 From: 101 Date: Thu, 25 Jan 2024 18:41:30 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=98=ED=99=98=ED=98=95=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20Boolean=20->=20response=20dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mail/api/MailController.java | 3 ++- .../domain/mail/service/MailVerify.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) 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) {