From 733fa7486ede31be096e73ce922b296de69aefda Mon Sep 17 00:00:00 2001 From: Minseo Kang Date: Thu, 14 Nov 2024 13:46:48 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=EB=8C=80=ED=95=99=EC=83=9D=20?= =?UTF-8?q?=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=9D=B8=EC=A6=9D=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20API=20=EC=9E=91=EC=84=B1=20(#103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: Controller 작성 * :art: 요청 dto 작성 * :art: 서비스 인터페이스 작성 * :sparkles: 서비스 로직 작성 * :art: 예외 작성 * :lock: 추적하지 않을 파일들 작성 * :memo: Swagger 문서 업데이트 --- .gitignore | 6 ++++ .../controller/CertificationController.java | 10 ++++++ .../CertificationControllerApi.java | 35 +++++++++++++++++++ .../dto/ClearCertificateUnivAuthReq.java | 9 +++++ .../exception/CertificateErrorCode.java | 3 +- .../EmailClearBadRequestException.java | 10 ++++++ .../service/CertificationService.java | 2 ++ .../service/CertificationServiceImpl.java | 11 ++++++ 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/example/gather_back_end/certification/dto/ClearCertificateUnivAuthReq.java create mode 100644 src/main/java/org/example/gather_back_end/certification/exception/EmailClearBadRequestException.java diff --git a/.gitignore b/.gitignore index 3b6f2d6..6163f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,9 @@ out/ ### .env ### .env.* .env + +### application ### +application.yml +application-*.yml +application.properties +application-*.properties diff --git a/src/main/java/org/example/gather_back_end/certification/controller/CertificationController.java b/src/main/java/org/example/gather_back_end/certification/controller/CertificationController.java index f9d287f..219d167 100644 --- a/src/main/java/org/example/gather_back_end/certification/controller/CertificationController.java +++ b/src/main/java/org/example/gather_back_end/certification/controller/CertificationController.java @@ -6,6 +6,7 @@ import org.example.gather_back_end.certification.dto.CertificateUnivAuthReq; import org.example.gather_back_end.certification.dto.CertificateUnivEmailReq; import org.example.gather_back_end.certification.dto.CertificationEntrepreneurValidateReq; +import org.example.gather_back_end.certification.dto.ClearCertificateUnivAuthReq; import org.example.gather_back_end.certification.service.CertificationService; import org.example.gather_back_end.util.jwt.dto.CustomOAuth2User; import org.example.gather_back_end.util.response.SuccessResponse; @@ -44,6 +45,15 @@ public SuccessResponse certificateUnivAuth( return SuccessResponse.of(null); } + // 인증된 이메일 초기화 + @PostMapping("/univ/clear") + public SuccessResponse clearCertificateUnivAuth( + @RequestBody ClearCertificateUnivAuthReq req + ) throws IOException { + certificationService.clearCertificateUnivAuth(req); + return SuccessResponse.of(null); + } + // 사업자 번호 인증 (validate + status 검증) @PostMapping("/entrepreneur") public SuccessResponse certificationEntrepreneur( diff --git a/src/main/java/org/example/gather_back_end/certification/controller/CertificationControllerApi.java b/src/main/java/org/example/gather_back_end/certification/controller/CertificationControllerApi.java index 5cdc368..964b2b7 100644 --- a/src/main/java/org/example/gather_back_end/certification/controller/CertificationControllerApi.java +++ b/src/main/java/org/example/gather_back_end/certification/controller/CertificationControllerApi.java @@ -11,6 +11,7 @@ import org.example.gather_back_end.certification.dto.CertificateUnivAuthReq; import org.example.gather_back_end.certification.dto.CertificateUnivEmailReq; import org.example.gather_back_end.certification.dto.CertificationEntrepreneurValidateReq; +import org.example.gather_back_end.certification.dto.ClearCertificateUnivAuthReq; import org.example.gather_back_end.util.response.SuccessResponse; import org.springframework.security.core.Authentication; import org.springframework.web.ErrorResponse; @@ -113,6 +114,40 @@ public interface CertificationControllerApi { @PostMapping SuccessResponse certificateUnivAuth(Authentication authentication, @RequestBody CertificateUnivAuthReq req) throws IOException; + @Operation(summary = "이메일 인증 초기화") + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "인증 초기화 성공", + content = @Content( + mediaType = "application/json", + examples = @ExampleObject( + value = "{\n" + + " \"timestamp\": \"2024-11-03T05:07:47.704694\",\n" + + " \"isSuccess\": true,\n" + + " \"code\": \"200\",\n" + + " \"message\": \"호출에 성공하였습니다.\",\n" + + " \"data\": null\n" + + "}" + ), + schema = @Schema(implementation = SuccessResponse.class) + ) + ), + @ApiResponse(responseCode = "400", description = "인증 초기화 실패(인증되지 않은 이메일에 대해 호출하면 발생)", + content = @Content(mediaType = "application/json", + examples = @ExampleObject(value = "{\n" + + " \"timestamp\": \"2024-11-03T15:44:24.484124\",\n" + + " \"isSuccess\": false,\n" + + " \"code\": \"EMAIL_CLEAR_BAD_REQUEST_400\",\n" + + " \"message\": \"이메일 인증 초기화 실패\",\n" + + " \"httpStatus\": 400\n" + + "}"), + schema = @Schema(implementation = SuccessResponse.class)) + ) + }) + @PostMapping + SuccessResponse clearCertificateUnivAuth(@RequestBody ClearCertificateUnivAuthReq req) throws IOException; + @Operation(summary = "사업자 인증", description = "사업자 인증 성공한 경우, data의 isSuccess 필드가 true\n" + "사업자 인증 실패 시, data의 isSuccess 필드가 false" diff --git a/src/main/java/org/example/gather_back_end/certification/dto/ClearCertificateUnivAuthReq.java b/src/main/java/org/example/gather_back_end/certification/dto/ClearCertificateUnivAuthReq.java new file mode 100644 index 0000000..670d415 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/certification/dto/ClearCertificateUnivAuthReq.java @@ -0,0 +1,9 @@ +package org.example.gather_back_end.certification.dto; + +import io.swagger.v3.oas.annotations.media.Schema; + +public record ClearCertificateUnivAuthReq( + @Schema(description = "학교 이메일", example = "kms2171344@hansung.ac.kr") + String email +) { +} diff --git a/src/main/java/org/example/gather_back_end/certification/exception/CertificateErrorCode.java b/src/main/java/org/example/gather_back_end/certification/exception/CertificateErrorCode.java index 087ada3..d667e76 100644 --- a/src/main/java/org/example/gather_back_end/certification/exception/CertificateErrorCode.java +++ b/src/main/java/org/example/gather_back_end/certification/exception/CertificateErrorCode.java @@ -14,7 +14,8 @@ public enum CertificateErrorCode implements BaseErrorCode { ENTREPRENEUR_BAD_REQUEST_EXCEPTION(BAD_REQUEST, "ENTREPRENEUR_BAD_REQUEST_400", "사업자 등록 정보가 일치하지 않음"), AUTH_NUMBER_NOT_MATCH_BAD_REQUEST(BAD_REQUEST, "AUTH_NUMBER_NOT_MATCH_BAD_REQUEST_400", "이메일로 전송된 코드와 인증번호가 일치하지 않음"), UNIV_NOT_FOUND_EXCEPTION(NOT_FOUND, "UNIV_NOT_FOUND_404", "올바르지 않은 대학명"), - EMAIL_BAD_REQUEST_EXCEPTION(BAD_REQUEST, "EMAIL_BAD_REQUEST_400", "존재하지 않는 이메일 주소"); + EMAIL_BAD_REQUEST_EXCEPTION(BAD_REQUEST, "EMAIL_BAD_REQUEST_400", "존재하지 않는 이메일 주소"), + EMAIL_CLEAR_BAD_REQUEST_EXCEPTION(BAD_REQUEST, "EMAIL_CLEAR_BAD_REQUEST_400", "이메일 인증 초기화 실패"); private final int httpStatus; private final String code; diff --git a/src/main/java/org/example/gather_back_end/certification/exception/EmailClearBadRequestException.java b/src/main/java/org/example/gather_back_end/certification/exception/EmailClearBadRequestException.java new file mode 100644 index 0000000..0cadcbf --- /dev/null +++ b/src/main/java/org/example/gather_back_end/certification/exception/EmailClearBadRequestException.java @@ -0,0 +1,10 @@ +package org.example.gather_back_end.certification.exception; + +import org.example.gather_back_end.util.exception.BaseException; + +public class EmailClearBadRequestException extends BaseException { + + public EmailClearBadRequestException() { + super(CertificateErrorCode.EMAIL_CLEAR_BAD_REQUEST_EXCEPTION); + } +} diff --git a/src/main/java/org/example/gather_back_end/certification/service/CertificationService.java b/src/main/java/org/example/gather_back_end/certification/service/CertificationService.java index 9d124e8..3dc13ba 100644 --- a/src/main/java/org/example/gather_back_end/certification/service/CertificationService.java +++ b/src/main/java/org/example/gather_back_end/certification/service/CertificationService.java @@ -4,10 +4,12 @@ import org.example.gather_back_end.certification.dto.CertificateUnivAuthReq; import org.example.gather_back_end.certification.dto.CertificateUnivEmailReq; import org.example.gather_back_end.certification.dto.CertificationEntrepreneurValidateReq; +import org.example.gather_back_end.certification.dto.ClearCertificateUnivAuthReq; public interface CertificationService { void certificateUnivEmail(CertificateUnivEmailReq req) throws IOException; void certificateUnivAuth(CertificateUnivAuthReq req, String providerId) throws IOException; + void clearCertificateUnivAuth(ClearCertificateUnivAuthReq req) throws IOException; void certificationEntrepreneurValidate(CertificationEntrepreneurValidateReq req, String providerId); } diff --git a/src/main/java/org/example/gather_back_end/certification/service/CertificationServiceImpl.java b/src/main/java/org/example/gather_back_end/certification/service/CertificationServiceImpl.java index abaf38f..c8d53af 100644 --- a/src/main/java/org/example/gather_back_end/certification/service/CertificationServiceImpl.java +++ b/src/main/java/org/example/gather_back_end/certification/service/CertificationServiceImpl.java @@ -11,6 +11,7 @@ import org.example.gather_back_end.certification.dto.CertificateUnivAuthReq; import org.example.gather_back_end.certification.dto.CertificateUnivEmailReq; import org.example.gather_back_end.certification.dto.CertificationEntrepreneurValidateReq; +import org.example.gather_back_end.certification.dto.ClearCertificateUnivAuthReq; import org.example.gather_back_end.certification.dto.GetEmailExistCheckRes; import org.example.gather_back_end.certification.dto.GetEntrepreneurStatusReq; import org.example.gather_back_end.certification.dto.GetEntrepreneurStatusRes; @@ -18,6 +19,7 @@ import org.example.gather_back_end.certification.dto.GetEntrepreneurValidateRes; import org.example.gather_back_end.certification.exception.AuthNumberNotMatchBadRequestException; import org.example.gather_back_end.certification.exception.EmailBadRequestException; +import org.example.gather_back_end.certification.exception.EmailClearBadRequestException; import org.example.gather_back_end.certification.exception.EntrepreneurBadRequestException; import org.example.gather_back_end.certification.exception.UnivNotFoundException; import org.example.gather_back_end.domain.User; @@ -81,6 +83,15 @@ public void certificateUnivAuth(CertificateUnivAuthReq req, String providerId) t throw new AuthNumberNotMatchBadRequestException(); } + @Override + public void clearCertificateUnivAuth(ClearCertificateUnivAuthReq req) throws IOException { + Map clear = UnivCert.clear(univCertApiKey, req.email()); + boolean isSuccess = (boolean) clear.get("success"); + if (!isSuccess) { + throw new EmailClearBadRequestException(); + } + } + // 사업자 등록 검증 @Override public void certificationEntrepreneurValidate(