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

Commit

Permalink
반환형 변경 Boolean -> response dto
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Jan 25, 2024
1 parent bd97002 commit 7a59f85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +28,7 @@ public Mono<Void> send(@RequestBody AuthCodeRequest request) {
}

@PostMapping("/verify")
public Mono<Boolean> verify(@RequestBody AuthCodeVerifyRequest request) {
public Mono<AuthCodeVerifyResponse> verify(@RequestBody AuthCodeVerifyRequest request) {
return mailVerify.execute(request);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,14 +19,26 @@ public MailVerify(AuthMailRepository authMailRepository, AuthCodeRepository auth
this.codeRepository = authCodeRepository;
}

public Mono<Boolean> execute(AuthCodeVerifyRequest request) {
public Mono<AuthCodeVerifyResponse> 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<AuthMail> save(String mail) {
Expand Down

0 comments on commit 7a59f85

Please sign in to comment.