diff --git a/be/src/main/java/yeonba/be/config/WebConfig.java b/be/src/main/java/yeonba/be/config/WebConfig.java index 6cea811a..265131de 100644 --- a/be/src/main/java/yeonba/be/config/WebConfig.java +++ b/be/src/main/java/yeonba/be/config/WebConfig.java @@ -23,6 +23,8 @@ public void addInterceptors(InterceptorRegistry registry) { .excludePathPatterns( "/users/join/**", "/users/login", - "/users/refresh"); + "/users/refresh", + "/users/nicknames/used", + "/users/phone-numbers/used"); } } diff --git a/be/src/main/java/yeonba/be/login/controller/LoginController.java b/be/src/main/java/yeonba/be/login/controller/LoginController.java index 0cdb327c..38309c38 100644 --- a/be/src/main/java/yeonba/be/login/controller/LoginController.java +++ b/be/src/main/java/yeonba/be/login/controller/LoginController.java @@ -5,7 +5,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -13,9 +15,13 @@ import yeonba.be.login.dto.request.UserJoinRequest; import yeonba.be.login.dto.request.UserLoginRequest; import yeonba.be.login.dto.request.UserRefreshJwtRequest; +import yeonba.be.login.dto.request.UserValidateUsedNicknameRequest; +import yeonba.be.login.dto.request.UserValidateUsedPhoneNumberRequest; import yeonba.be.login.dto.response.UserJoinResponse; import yeonba.be.login.dto.response.UserLoginResponse; import yeonba.be.login.dto.response.UserRefrehJwtResponse; +import yeonba.be.login.dto.response.UserValidateUsedNicknameResponse; +import yeonba.be.login.dto.response.UserValidateUsedPhoneNumberResponse; import yeonba.be.login.service.LoginService; import yeonba.be.user.service.JoinService; import yeonba.be.util.CustomResponse; @@ -66,4 +72,32 @@ public ResponseEntity> refreshJwt( .ok() .body(new CustomResponse<>(response)); } + + @Operation(summary = "사용 중인 닉네임 검증", description = "사용 중인 닉네임인 지 검증할 수 있습니다.") + @ApiResponse(responseCode = "200", description = "사용 중인 닉네임 검증 성공") + @GetMapping("/users/nicknames/used") + public ResponseEntity> validateUsedNickname( + @Valid @ParameterObject UserValidateUsedNicknameRequest request) { + + UserValidateUsedNicknameResponse response = + loginService.validateUsedNickname(request); + + return ResponseEntity + .ok() + .body(new CustomResponse<>(response)); + } + + @Operation(summary = "사용 중인 전화번호 검증", description = "사용 중인 전화번호 검증 가능") + @ApiResponse(responseCode = "200", description = "사용 중인 전화번호 검증 성공") + @GetMapping("/users/phone-numbers/used") + public ResponseEntity> validateUsedPhoneNumber( + @Valid @ParameterObject UserValidateUsedPhoneNumberRequest request) { + + UserValidateUsedPhoneNumberResponse response = + loginService.validateUsedPhoneNumber(request); + + return ResponseEntity + .ok() + .body(new CustomResponse<>(response)); + } } diff --git a/be/src/main/java/yeonba/be/login/dto/request/UserValidateUsedNicknameRequest.java b/be/src/main/java/yeonba/be/login/dto/request/UserValidateUsedNicknameRequest.java new file mode 100644 index 00000000..eb3e3db7 --- /dev/null +++ b/be/src/main/java/yeonba/be/login/dto/request/UserValidateUsedNicknameRequest.java @@ -0,0 +1,24 @@ +package yeonba.be.login.dto.request; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class UserValidateUsedNicknameRequest { + + @Parameter( + name = "nickname", + description = "닉네임", + example = "존존예녀", + in = ParameterIn.QUERY) + @Pattern( + regexp = "^[a-zA-Z0-9가-힣]{1,8}$", + message = "닉네임은 공백 없이 영어 대소문자,한글,숫자로 구성되어야 하며 최대 8자까지 가능합니다.") + @NotBlank(message = "닉네임은 반드시 입력되어야 합니다.") + private String nickname; +} diff --git a/be/src/main/java/yeonba/be/login/dto/request/UserVerificationCodeRequest.java b/be/src/main/java/yeonba/be/login/dto/request/UserValidateUsedPhoneNumberRequest.java similarity index 60% rename from be/src/main/java/yeonba/be/login/dto/request/UserVerificationCodeRequest.java rename to be/src/main/java/yeonba/be/login/dto/request/UserValidateUsedPhoneNumberRequest.java index 61173fc6..da0d2535 100644 --- a/be/src/main/java/yeonba/be/login/dto/request/UserVerificationCodeRequest.java +++ b/be/src/main/java/yeonba/be/login/dto/request/UserValidateUsedPhoneNumberRequest.java @@ -1,19 +1,21 @@ package yeonba.be.login.dto.request; -import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor -public class UserVerificationCodeRequest { +@AllArgsConstructor +public class UserValidateUsedPhoneNumberRequest { - @Schema( - type = "string", + @Parameter( + name = "phoneNumber", description = "전화번호", - example = "01011112222") + example = "01011112222", + in = ParameterIn.QUERY) @Pattern( regexp = "^010\\d{8}$", message = "전화번호는 11자리 010으로 시작하며 하이픈(-) 없이 0~9의 숫자로 이뤄져야 합니다.") diff --git a/be/src/main/java/yeonba/be/login/dto/request/UserVerifyPhoneNumberRequest.java b/be/src/main/java/yeonba/be/login/dto/request/UserVerifyPhoneNumberRequest.java deleted file mode 100644 index 9a155889..00000000 --- a/be/src/main/java/yeonba/be/login/dto/request/UserVerifyPhoneNumberRequest.java +++ /dev/null @@ -1,32 +0,0 @@ -package yeonba.be.login.dto.request; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Pattern; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor -public class UserVerifyPhoneNumberRequest { - - @Schema( - type = "string", - description = "인증 번호를 받은 번호", - example = "01011112222") - @Pattern( - regexp = "^010\\d{8}$", - message = "전화번호는 11자리 010으로 시작하며 하이픈(-) 없이 0~9의 숫자로 이뤄져야 합니다.") - @NotBlank(message = "전화번호는 반드시 입력되어야 합니다.") - private String phoneNumber; - - @Schema( - type = "string", - description = "아이디 찾기 인증 코드", - example = "A1b2C3") - @Pattern( - regexp = "^[A-Za-z0-9]{6}$", - message = "인증 코드는 6자리로 영어대소문자, 숫자로만 이뤄져야 합니다.") - @NotBlank(message = "인증 코드는 반드시 입력되어야 합니다.") - private String verificationCode; -} diff --git a/be/src/main/java/yeonba/be/login/dto/response/UserValidateUsedNicknameResponse.java b/be/src/main/java/yeonba/be/login/dto/response/UserValidateUsedNicknameResponse.java new file mode 100644 index 00000000..d81e01a0 --- /dev/null +++ b/be/src/main/java/yeonba/be/login/dto/response/UserValidateUsedNicknameResponse.java @@ -0,0 +1,18 @@ +package yeonba.be.login.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class UserValidateUsedNicknameResponse { + + @Schema( + type = "boolean", + description = "닉네임 사용 여부", + example = "false") + @JsonProperty("isUsedNickname") + private boolean usedNickname; +} diff --git a/be/src/main/java/yeonba/be/login/dto/response/UserValidateUsedPhoneNumberResponse.java b/be/src/main/java/yeonba/be/login/dto/response/UserValidateUsedPhoneNumberResponse.java new file mode 100644 index 00000000..41cb5996 --- /dev/null +++ b/be/src/main/java/yeonba/be/login/dto/response/UserValidateUsedPhoneNumberResponse.java @@ -0,0 +1,18 @@ +package yeonba.be.login.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class UserValidateUsedPhoneNumberResponse { + + @Schema( + type = "boolean", + description = "전화번호 사용 여부", + example = "false") + @JsonProperty("isUsedPhoneNumber") + private boolean usedPhoneNumber; +} diff --git a/be/src/main/java/yeonba/be/login/service/LoginService.java b/be/src/main/java/yeonba/be/login/service/LoginService.java index 33ace0b0..6d2f33de 100644 --- a/be/src/main/java/yeonba/be/login/service/LoginService.java +++ b/be/src/main/java/yeonba/be/login/service/LoginService.java @@ -8,8 +8,12 @@ import yeonba.be.exception.UserException; import yeonba.be.login.dto.request.UserLoginRequest; import yeonba.be.login.dto.request.UserRefreshJwtRequest; +import yeonba.be.login.dto.request.UserValidateUsedNicknameRequest; +import yeonba.be.login.dto.request.UserValidateUsedPhoneNumberRequest; import yeonba.be.login.dto.response.UserLoginResponse; import yeonba.be.login.dto.response.UserRefrehJwtResponse; +import yeonba.be.login.dto.response.UserValidateUsedNicknameResponse; +import yeonba.be.login.dto.response.UserValidateUsedPhoneNumberResponse; import yeonba.be.user.entity.User; import yeonba.be.user.enums.LoginType; import yeonba.be.user.repository.user.UserQuery; @@ -63,4 +67,22 @@ public UserRefrehJwtResponse refreshJwt(UserRefreshJwtRequest request) { return new UserRefrehJwtResponse(jwt, refreshToken); } + + @Transactional(readOnly = true) + public UserValidateUsedNicknameResponse validateUsedNickname( + UserValidateUsedNicknameRequest request) { + + boolean usedNickname = userQuery.validateUsedNickname(request.getNickname()); + + return new UserValidateUsedNicknameResponse(usedNickname); + } + + @Transactional(readOnly = true) + public UserValidateUsedPhoneNumberResponse validateUsedPhoneNumber( + UserValidateUsedPhoneNumberRequest request) { + + boolean usedPhoneNumber = userQuery.validateUsedPhoneNumber(request.getPhoneNumber()); + + return new UserValidateUsedPhoneNumberResponse(usedPhoneNumber); + } }