Skip to content

Commit

Permalink
✨ 대학생 이메일 인증 초기화 API 작성 (#103)
Browse files Browse the repository at this point in the history
* ✨ Controller 작성

* 🎨 요청 dto 작성

* 🎨 서비스 인터페이스 작성

* ✨ 서비스 로직 작성

* 🎨 예외 작성

* 🔒 추적하지 않을 파일들 작성

* 📝 Swagger 문서 업데이트
  • Loading branch information
MinseoKangQ authored and Jindongleee committed Nov 16, 2024
1 parent 2a30516 commit 733fa74
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ out/
### .env ###
.env.*
.env

### application ###
application.yml
application-*.yml
application.properties
application-*.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]")
String email
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
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;
import org.example.gather_back_end.certification.dto.GetEntrepreneurValidateReq;
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;
Expand Down Expand Up @@ -81,6 +83,15 @@ public void certificateUnivAuth(CertificateUnivAuthReq req, String providerId) t
throw new AuthNumberNotMatchBadRequestException();
}

@Override
public void clearCertificateUnivAuth(ClearCertificateUnivAuthReq req) throws IOException {
Map<String, Object> clear = UnivCert.clear(univCertApiKey, req.email());
boolean isSuccess = (boolean) clear.get("success");
if (!isSuccess) {
throw new EmailClearBadRequestException();
}
}

// 사업자 등록 검증
@Override
public void certificationEntrepreneurValidate(
Expand Down

0 comments on commit 733fa74

Please sign in to comment.