Skip to content

Commit

Permalink
[Feature] #298 - 문자 메시지 전송 및 인증 API (Controller)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjKim1229 committed Jul 11, 2023
1 parent 532980b commit 14d87ce
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/main/java/shop/cazait/domain/auth/api/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package shop.cazait.domain.auth.api;

import static shop.cazait.global.error.status.SuccessStatus.ACCEPTED_SEND_MESSAGE;
import static shop.cazait.global.error.status.SuccessStatus.SUCCESS;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -21,6 +26,10 @@

import shop.cazait.domain.auth.dto.UserAuthenticateInDTO;
import shop.cazait.domain.auth.dto.UserAuthenticateOutDTO;
import shop.cazait.domain.auth.dto.sens.AuthSendMessageCodeInDTO;
import shop.cazait.domain.auth.dto.sens.AuthSendMessageCodeOutDTO;
import shop.cazait.domain.auth.dto.sens.AuthVerifyMessageCodeInDTO;
import shop.cazait.domain.auth.dto.sens.AuthVerifyMessageCodeOutDTO;
import shop.cazait.domain.auth.service.AuthService;
import shop.cazait.domain.master.error.MasterException;
import shop.cazait.domain.user.exception.UserException;
Expand All @@ -36,7 +45,6 @@
@RequestMapping("/api/auths")
public class AuthController {


private final JwtService jwtService;

private final AuthService authService;
Expand All @@ -55,7 +63,6 @@ public SuccessResponse<UserAuthenticateOutDTO> logIn(
return new SuccessResponse<>(SUCCESS, userAuthenticateOutDTO);
}


@NoAuth
@GetMapping(value = "/refresh")
@Operation(summary = "토큰 재발급", description = "인터셉터에서 accesstoken이 만료되고 난 후 클라이언트에서 해당 api로 토큰 재발급 요청 필요")
Expand All @@ -72,6 +79,34 @@ public SuccessResponse<UserAuthenticateOutDTO> refreshToken(
UserAuthenticateOutDTO userAuthenticateOutDTO = authService.reIssueTokensByRole(exactRole, accessToken, refreshToken);
return new SuccessResponse<>(SUCCESS, userAuthenticateOutDTO);
}

@NoAuth
@PostMapping("/messages/codes/send")
@Operation(summary = "문자 인증번호 발송", description = "인증 문자 받을 번호 입력하여, 인증 문자 발송")
public SuccessResponse<AuthSendMessageCodeOutDTO> sendMessageCode(@RequestBody AuthSendMessageCodeInDTO userSensAuthenticateInDTO) throws NoSuchAlgorithmException, URISyntaxException, UnsupportedEncodingException, InvalidKeyException, JsonProcessingException, UnsupportedEncodingException, JsonProcessingException {
String recipientPhoneNumber = userSensAuthenticateInDTO.getRecipientPhoneNumber();
AuthSendMessageCodeOutDTO authSendMessageCodeOutDTO = authService.sendMessageCode(recipientPhoneNumber);
return new SuccessResponse<>(ACCEPTED_SEND_MESSAGE, authSendMessageCodeOutDTO);
}

@NoAuth
@PostMapping("/messages/codes/send/test")
@Operation(summary = "문자 인증번호 발송 테스트", description = "실제로 문자 발송은 진행하지 않음")
public SuccessResponse<AuthSendMessageCodeOutDTO> sendMessageCodeTest(@RequestBody AuthSendMessageCodeInDTO userSensAuthenticateInDTO) throws NoSuchAlgorithmException, URISyntaxException, UnsupportedEncodingException, InvalidKeyException, JsonProcessingException, UnsupportedEncodingException, JsonProcessingException {
String recipientPhoneNumber = userSensAuthenticateInDTO.getRecipientPhoneNumber();
AuthSendMessageCodeOutDTO authSendMessageCodeOutDTO = authService.sendMessageCodeTest(recipientPhoneNumber);
return new SuccessResponse<>(ACCEPTED_SEND_MESSAGE, authSendMessageCodeOutDTO);
}

@NoAuth
@PostMapping("/messages/codes/verify")
@Operation(summary = "문자 인증번호 인증", description = "문자로 받은 인증 번호를 입력하여, 적절한 인증번호인지 판단")
public SuccessResponse<AuthVerifyMessageCodeOutDTO>verifyMessageCode(@RequestBody AuthVerifyMessageCodeInDTO authVerifyMessageCodeInDTO) throws UserException {
String recipientPhoneNumber = authVerifyMessageCodeInDTO.getRecipientPhoneNumber();
Integer verificationCode = authVerifyMessageCodeInDTO.getVerificationCode();
AuthVerifyMessageCodeOutDTO authVerifyMessageCodeOutDTO = authService.verifyMessageCode(recipientPhoneNumber, verificationCode);
return new SuccessResponse<>(SUCCESS, authVerifyMessageCodeOutDTO);
}
}

// @NoAuth
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package shop.cazait.domain.auth.dto.sens;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;


@Schema(description = "문자 인증 (전송) 결과 Response : 문자 인증 (전송)시 Response 정보 ")
@Getter
@Builder
public class ExtSensSendMessageCodeOutDTO {
@Schema(description = "요청 아이디")
@NotBlank
private String requestId;

@Schema(description = "요청 시간", example = "2023-07-06T16:55:25.972")
@NotBlank
private LocalDateTime requestTime;
@Schema(description = "요청 상태 코드(202 : 성공, 그 외: 실패)", example = "202")
@NotBlank
private String statusCode;
@Schema(description = "요청 상태명", example = "success: 성공, fail: 실패")
@NotBlank
private String statusName;

@Builder
ExtSensSendMessageCodeOutDTO(String requestId, LocalDateTime requestTime, String statusCode, String statusName){
this.requestId = requestId;
this.requestTime = requestTime;
this.statusCode = statusCode;
this.statusName = statusName;
}
}

0 comments on commit 14d87ce

Please sign in to comment.