Skip to content

Commit

Permalink
[닉네임, 전화번호] 닉네임, 전화번호 사용 여부 검증(#78) (#79)
Browse files Browse the repository at this point in the history
* feat: 불필요한 미사용 코드 삭제(#78)

* feat: 사용 중인 닉네임 검증 요청 DTO 추가(#78)

* feat: 사용 중인 닉네임 검증 응답 DTO 추가(#78)

* feat: 사용 중인 닉네임 검증 로직 추가(#78)

* feat: 사용 중인 닉네임 검증 API 추가(#78)

* feat: 사용 중인 닉네임 확인 API, 인가 대상에서 제외(#78)

회원 가입 과정 중 이미 사용 중인 닉네임인 지 여부를 확인하기 위해 사용.
인가 과정이 필요하지 않음.

* feat: 사용 중인 전화번호 검증 요청 DTO 추가(#78)

* feat: 사용 중인 전화번호 검증 응답 DTO 추가(#78)

* docs: 명세에 필드 값 예시 추가(#78)

* docs: 명세 설명 수정(#78)

* feat: 사용 중인 전화번호 검증 로직 추가(#78)

* feat: 사용 중인 전화번호 검증 API 추가(#78)

* feat: 사용 중인 전화번호 검증 API, 인가 대상에서 제외(#78)

회원 가입시 사용 중인 전화번호 검증을 위해 사용하기 때문에 인가 대상에서 제외

* refactor: 코드 정렬 수정(#78)
  • Loading branch information
Minjae-An authored May 13, 2024
1 parent 68154a2 commit f4011d4
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 40 deletions.
4 changes: 3 additions & 1 deletion be/src/main/java/yeonba/be/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
34 changes: 34 additions & 0 deletions be/src/main/java/yeonba/be/login/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
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;
import org.springframework.web.bind.annotation.RestController;
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;
Expand Down Expand Up @@ -66,4 +72,32 @@ public ResponseEntity<CustomResponse<UserRefrehJwtResponse>> refreshJwt(
.ok()
.body(new CustomResponse<>(response));
}

@Operation(summary = "사용 중인 닉네임 검증", description = "사용 중인 닉네임인 지 검증할 수 있습니다.")
@ApiResponse(responseCode = "200", description = "사용 중인 닉네임 검증 성공")
@GetMapping("/users/nicknames/used")
public ResponseEntity<CustomResponse<UserValidateUsedNicknameResponse>> 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<CustomResponse<UserValidateUsedPhoneNumberResponse>> validateUsedPhoneNumber(
@Valid @ParameterObject UserValidateUsedPhoneNumberRequest request) {

UserValidateUsedPhoneNumberResponse response =
loginService.validateUsedPhoneNumber(request);

return ResponseEntity
.ok()
.body(new CustomResponse<>(response));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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의 숫자로 이뤄져야 합니다.")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions be/src/main/java/yeonba/be/login/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f4011d4

Please sign in to comment.