Skip to content

Commit

Permalink
#189 docs: 인증번호 조회 및 마이페이지 알림 수신여부 스웨거 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
chaerlo127 committed Nov 10, 2023
1 parent c92a326 commit 4688fca
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ enum class BaseResponseCode(status: HttpStatus, message: String) {
INVALID_EID(HttpStatus.BAD_REQUEST, "정상 사업자가 아닙니다. (휴업자 or 폐업자)"),
DUPLICATE_PASSWORD(HttpStatus.BAD_REQUEST, "사용자의 비밀번호와 변경하려는 비밀번호가 동일합니다."),
PHONE_ERROR(HttpStatus.BAD_REQUEST, "naver SMS API 관련 에러입니다."),
BLACKLIST_PHONE(HttpStatus.BAD_REQUEST, "SMS 인증코드 유효 시간이 만료되었습니다."),
INVALID_SMS_KEY(HttpStatus.BAD_REQUEST, "SMS 인증코드가 알맞지 않습니다. "),
BLACKLIST_PHONE(HttpStatus.FORBIDDEN, "SMS 인증코드 유효 시간이 만료되었습니다."),
INVALID_SMS_KEY(HttpStatus.BAD_REQUEST, "SMS 인증코드가 알맞지 않습니다."),

// User - type
INVALID_USER_TYPE_NAME(HttpStatus.BAD_REQUEST, "올바르지 않은 사용자 역할입니다."),
Expand Down
57 changes: 48 additions & 9 deletions src/main/kotlin/com/psr/psr/user/controller/UserController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -361,42 +361,81 @@ class UserController(
ApiResponse(responseCode = "200", description = "요청에 성공했습니다."),
ApiResponse(
responseCode = "400",
description = "naver SMS API 관련 에러입니다.<br>" +
"이미 가입되어 있는 휴대폰 번호입니다.",
description = "SMS 인증코드가 알맞지 않습니다.<br>",
content = arrayOf(Content(schema = Schema(implementation = BaseResponse::class)))
),ApiResponse(
responseCode = "403",
description = "SMS 인증코드 유효 시간이 만료되었습니다.<br>",
content = arrayOf(Content(schema = Schema(implementation = BaseResponse::class)))
)]
)
@PostMapping("/phone/validation")
fun checkValidSmsKey(@RequestBody @Validated validPhoneReq: ValidPhoneReq) : BaseResponse<Any>{
userService.checkValidSmsKey(validPhoneReq.phone, validPhoneReq.smsKey!!)
userService.checkValidSmsKey(validPhoneReq.phone, validPhoneReq.smsKey)
return BaseResponse(BaseResponseCode.SUCCESS)
}

/**
* 아이디 + 인증번호 조회
*/
@Operation(summary = "[토큰 X] 아이디 찾기를 위한 인증번호 조회 (장채은)", description = "휴대폰 번호로 휴대폰 인증번호 일치를 조회한다.")
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "요청에 성공했습니다."),
ApiResponse(
responseCode = "400",
description = "SMS 인증코드가 알맞지 않습니다.<br>" +
"사용자를 찾을 수 없습니다.<br>" +
"올바르지 않은 휴대폰 형식입니다.<br>" +
"variable + 을(를) 입력해주세요.",
content = arrayOf(Content(schema = Schema(implementation = BaseResponse::class)))
),ApiResponse(
responseCode = "403",
description = "SMS 인증코드 유효 시간이 만료되었습니다.<br>",
content = arrayOf(Content(schema = Schema(implementation = BaseResponse::class)))
)]
)
@PostMapping("/email/search")
fun findEmailSearch(@RequestBody @Validated findIdPwReq: FindIdPwReq): BaseResponse<EmailRes>{
if(!StringUtils.hasText(findIdPwReq.name)) throw BaseException(BaseResponseCode.NOT_EMPTY_NAME)
return BaseResponse(userService.findEmailSearch(findIdPwReq))
fun findEmailSearch(@RequestBody @Validated findIdReq: FindIdReq): BaseResponse<EmailRes>{
return BaseResponse(userService.findEmailSearch(findIdReq))
}

/**
* 비밀번호 변경 + 인증번호 조회
*/
@Operation(summary = "[토큰 X] 비밀번호 재설정을 위한 인증번호 조회 (장채은)", description = "이메일 + 휴대폰 번호로 휴대폰 인증번호 일치를 조회한다.")
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "요청에 성공했습니다."),
ApiResponse(
responseCode = "400",
description = "SMS 인증코드가 알맞지 않습니다.<br>" +
"사용자를 찾을 수 없습니다.<br>" +
"올바르지 않은 휴대폰 형식입니다.<br>" +
"올바르지 않은 이메일 형식입니다.<br>" +
"variable + 을(를) 입력해주세요.",
content = arrayOf(Content(schema = Schema(implementation = BaseResponse::class)))
),ApiResponse(
responseCode = "403",
description = "SMS 인증코드 유효 시간이 만료되었습니다.<br>",
content = arrayOf(Content(schema = Schema(implementation = BaseResponse::class)))
)]
)
@PostMapping("/password")
fun findPWSearch(@RequestBody @Validated findIdPwReq: FindIdPwReq): BaseResponse<Any>{
if(!StringUtils.hasText(findIdPwReq.email)) throw BaseException(BaseResponseCode.NOT_EMPTY_EMAIL)
userService.findPWSearch(findIdPwReq)
fun findPWSearch(@RequestBody @Validated findPwReq: FindPwReq): BaseResponse<Any>{
userService.findPWSearch(findPwReq)
return BaseResponse(BaseResponseCode.SUCCESS)
}

/**
* 마이페이지 알림 수신 여부
*/
@Operation(summary = "마이페이지 알림 수신 여부 (장채은)", description = "알림 수신 여부를 변경한다.")
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "요청에 성공했습니다.")
]
)
@PostMapping("/notification")
fun postNotiStatus(@AuthenticationPrincipal userAccount: UserAccount): BaseResponse<Any>{
return BaseResponse(userService.postNotiStatus(userAccount.getUser()))
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/com/psr/psr/user/dto/phoneReq/SMSReq.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.psr.psr.user.dto.phoneReq

import com.psr.psr.user.dto.request.ValidPhoneReq

data class SMSReq (
val type: String?= "SMS",
val contentType: String?="COMM",
Expand Down
19 changes: 0 additions & 19 deletions src/main/kotlin/com/psr/psr/user/dto/request/FindIdPwReq.kt

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/kotlin/com/psr/psr/user/dto/request/FindIdReq.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.psr.psr.user.dto.request

import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotEmpty
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern


data class FindIdReq (
@field:Pattern(
regexp = "^01([0|1|6|7|8|9])-?([0-9]{3,4})-?([0-9]{4})\$",
message = "올바르지 않은 휴대폰 형식입니다."
)
@NotBlank
@Schema(type = "String", description = "휴대폰", example = "010-0000-0000", required = true)
val phone: String,
@NotBlank
@Schema(type = "String", description = "인증코드", example = "12454", required = true)
val smsKey: String,
@NotBlank
@Schema(type = "String", description = "이름", example = "홍길동", required = true)
val name: String
)
24 changes: 24 additions & 0 deletions src/main/kotlin/com/psr/psr/user/dto/request/FindPwReq.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.psr.psr.user.dto.request

import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Pattern


data class FindPwReq (
@field:Pattern(
regexp = "^01([0|1|6|7|8|9])-?([0-9]{3,4})-?([0-9]{4})\$",
message = "올바르지 않은 휴대폰 형식입니다."
)
@NotBlank
@Schema(type = "String", description = "휴대폰", example = "010-0000-0000", required = true)
val phone: String,
@NotBlank
@Schema(type = "String", description = "인증코드", example = "12454", required = true)
val smsKey: String,
@NotBlank
@field:Email(message = "올바르지 않은 이메일 형식입니다.")
@Schema(type = "String", description = "이메일", example = "[email protected]", required = true)
val email: String
)
5 changes: 3 additions & 2 deletions src/main/kotlin/com/psr/psr/user/dto/request/ValidPhoneReq.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class ValidPhoneReq (
@field:NotBlank
@Schema(type = "String", description = "휴대폰", example = "010-0000-0000", required = true)
val phone: String,
@Schema(type = "String", description = "인증코드", example = "12454")
val smsKey: String ?= null
@field:NotBlank
@Schema(type = "String", description = "인증코드", example = "12454", required = true)
val smsKey: String
)
2 changes: 2 additions & 0 deletions src/main/kotlin/com/psr/psr/user/dto/response/EmailRes.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.psr.psr.user.dto.response

import com.psr.psr.user.entity.User
import io.swagger.v3.oas.annotations.media.Schema


data class EmailRes(
@Schema(type = "String", description = "이메일", example = "[email protected]", required = true)
val email: String,
){
companion object{
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/psr/psr/user/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,19 @@ class UserService(
}

// 이메일 찾기를 위한 인증
fun findEmailSearch(findIdPwReq: FindIdPwReq): EmailRes {
fun findEmailSearch(findIdReq: FindIdReq): EmailRes {
// 인증번호 확인
checkValidSmsKey(findIdPwReq.phone, findIdPwReq.smsKey)
val user: User = userRepository.findByNameAndPhoneAndStatus(findIdPwReq.name!!, findIdPwReq.phone, ACTIVE_STATUS) ?: throw BaseException(NOT_FOUND_USER)
checkValidSmsKey(findIdReq.phone, findIdReq.smsKey)
val user: User = userRepository.findByNameAndPhoneAndStatus(findIdReq.name, findIdReq.phone, ACTIVE_STATUS) ?: throw BaseException(NOT_FOUND_USER)
// 사용자 이메일 전달
return EmailRes.toEmailResDto(user)
}

// 비밀번호 변경을 위한 인증
fun findPWSearch(findIdPwReq: FindIdPwReq) {
fun findPWSearch(findIdPwReq: FindPwReq) {
// 인증번호 확인
checkValidSmsKey(findIdPwReq.phone, findIdPwReq.smsKey)
userRepository.findByEmailAndPhoneAndStatus(findIdPwReq.email!!, findIdPwReq.phone, ACTIVE_STATUS) ?: throw BaseException(NOT_FOUND_USER)
userRepository.findByEmailAndPhoneAndStatus(findIdPwReq.email, findIdPwReq.phone, ACTIVE_STATUS) ?: throw BaseException(NOT_FOUND_USER)
}

// 마이페이지 알림 수신 여부
Expand Down

0 comments on commit 4688fca

Please sign in to comment.