From 1b1e913577b7fff9a4dfed0220bb31f591c60345 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Thu, 11 Jul 2024 08:40:12 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[FEAT/#61]=20NicknameRequest=20DTO=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seonyakServer/domain/member/dto/NicknameRequest.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/org/sopt/seonyakServer/domain/member/dto/NicknameRequest.java diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/dto/NicknameRequest.java b/src/main/java/org/sopt/seonyakServer/domain/member/dto/NicknameRequest.java new file mode 100644 index 0000000..5766b87 --- /dev/null +++ b/src/main/java/org/sopt/seonyakServer/domain/member/dto/NicknameRequest.java @@ -0,0 +1,9 @@ +package org.sopt.seonyakServer.domain.member.dto; + +public record NicknameRequest( + String nickname +) { + public static NicknameRequest of(final String nickname) { + return new NicknameRequest(nickname); + } +} From a73b9f3eb57aa58395b5e0dc3f087a198b0bf19f Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Thu, 11 Jul 2024 08:42:56 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[FEAT/#61]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/repository/MemberRepository.java | 2 ++ .../domain/member/service/MemberService.java | 14 ++++++++++++++ .../global/common/RegularExpression.java | 6 ++++++ .../global/exception/enums/ErrorType.java | 1 + 4 files changed, 23 insertions(+) create mode 100644 src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java index a5b91d8..48c4850 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java @@ -7,4 +7,6 @@ public interface MemberRepository extends JpaRepository { Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId); + + boolean existsByNickname(String nickname); } diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index fdcf52c..7df804d 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -1,7 +1,10 @@ package org.sopt.seonyakServer.domain.member.service; +import static org.sopt.seonyakServer.global.common.RegularExpression.NICKNAME_PATTERN; + import lombok.RequiredArgsConstructor; import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse; +import org.sopt.seonyakServer.domain.member.dto.NicknameRequest; import org.sopt.seonyakServer.domain.member.model.Member; import org.sopt.seonyakServer.domain.member.model.SocialType; import org.sopt.seonyakServer.domain.member.repository.MemberRepository; @@ -87,4 +90,15 @@ public LoginSuccessResponse getTokenByMemberId(final Long id) { return LoginSuccessResponse.of(jwtTokenProvider.issueAccessToken(memberAuthentication)); } + + // 닉네임 유효성 검증 + public void validNickname(final NicknameRequest nicknameRequest) { + if (!nicknameRequest.nickname().matches(NICKNAME_PATTERN)) { // 형식 체크 + throw new CustomException(ErrorType.INVALID_NICKNAME_ERROR); + } + + if (memberRepository.existsByNickname(nicknameRequest.nickname())) { // 중복 체크 + throw new CustomException(ErrorType.NICKNAME_DUP_ERROR); + } + } } diff --git a/src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java b/src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java new file mode 100644 index 0000000..aa7ac24 --- /dev/null +++ b/src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java @@ -0,0 +1,6 @@ +package org.sopt.seonyakServer.global.common; + +public class RegularExpression { + + public static final String NICKNAME_PATTERN = "^[a-zA-Z0-9가-힣]{2,8}$"; +} diff --git a/src/main/java/org/sopt/seonyakServer/global/exception/enums/ErrorType.java b/src/main/java/org/sopt/seonyakServer/global/exception/enums/ErrorType.java index e328d60..d6e9ab2 100644 --- a/src/main/java/org/sopt/seonyakServer/global/exception/enums/ErrorType.java +++ b/src/main/java/org/sopt/seonyakServer/global/exception/enums/ErrorType.java @@ -22,6 +22,7 @@ public enum ErrorType { INVALID_CODE_HEADER_ERROR(HttpStatus.BAD_REQUEST, "40007", "code 헤더값의 형식이 잘못되었습니다."), INVALID_SOCIAL_TYPE_ERROR(HttpStatus.BAD_REQUEST, "40008", "유효하지 않은 Social Type입니다."), BEARER_LOST_ERROR(HttpStatus.BAD_REQUEST, "40009", "요청한 토큰이 Bearer 토큰이 아닙니다."), + INVALID_NICKNAME_ERROR(HttpStatus.BAD_REQUEST, "40010", "닉네임이 조건을 만족하지 않습니다."), MAP_TO_JSON_ERROR(HttpStatus.BAD_REQUEST, "40016", "Map을 JSON 문자열로 변환하는 중 오류가 발생했습니다."), JSON_TO_MAP_ERROR(HttpStatus.BAD_REQUEST, "40017", "JSON 문자열을 Map으로 변환하는 중 오류가 발생했습니다."), From 4d5f4d48d97a6d29731f8f19952fb2538b98fb87 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Thu, 11 Jul 2024 08:43:13 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[FEAT/#61]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EC=97=94?= =?UTF-8?q?=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java index 3439abd..0cbe6f8 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java @@ -3,7 +3,9 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse; +import org.sopt.seonyakServer.domain.member.dto.NicknameRequest; import org.sopt.seonyakServer.domain.member.service.MemberService; +import org.sopt.seonyakServer.global.common.dto.ResponseDto; import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -14,16 +16,25 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/auth") +@RequestMapping("/api/v1") public class MemberController { private final MemberService memberService; - @PostMapping("/login") + @PostMapping("/auth/login") public ResponseEntity login( @RequestParam final String authorizationCode, @RequestBody @Valid final MemberLoginRequest loginRequest ) { return ResponseEntity.ok(memberService.create(authorizationCode, loginRequest)); } + + @PostMapping("/nickname") + public ResponseDto validNickname( + @RequestBody final NicknameRequest nicknameRequest + ) { + memberService.validNickname(nicknameRequest); + + return ResponseDto.success(null); + } } From 1141b16b780aefe21349d90c376443906b7e9b8f Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Thu, 11 Jul 2024 23:23:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[DEL/#61]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RegularExpression --- .../seonyakServer/domain/member/service/MemberService.java | 4 ++-- .../sopt/seonyakServer/global/common/RegularExpression.java | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index 7df804d..97f954d 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -1,7 +1,5 @@ package org.sopt.seonyakServer.domain.member.service; -import static org.sopt.seonyakServer.global.common.RegularExpression.NICKNAME_PATTERN; - import lombok.RequiredArgsConstructor; import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse; import org.sopt.seonyakServer.domain.member.dto.NicknameRequest; @@ -27,6 +25,8 @@ public class MemberService { private final GoogleSocialService googleSocialService; private final MemberManagementService memberManagementService; + public static final String NICKNAME_PATTERN = "^[a-zA-Z0-9가-힣]{2,8}$"; + // JWT Access Token 생성 public LoginSuccessResponse create( final String authorizationCode, diff --git a/src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java b/src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java deleted file mode 100644 index aa7ac24..0000000 --- a/src/main/java/org/sopt/seonyakServer/global/common/RegularExpression.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.sopt.seonyakServer.global.common; - -public class RegularExpression { - - public static final String NICKNAME_PATTERN = "^[a-zA-Z0-9가-힣]{2,8}$"; -} From acf826fee9c4a779e45a15c0d8f7a91de1f6039d Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Thu, 11 Jul 2024 23:24:36 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[FIX/#61]=20validNickname=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EA=B0=92=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A4=80?= =?UTF-8?q?=EC=88=98=ED=95=98=EA=B2=8C=EB=81=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java index 0cbe6f8..9d43b17 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java @@ -5,7 +5,6 @@ import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse; import org.sopt.seonyakServer.domain.member.dto.NicknameRequest; import org.sopt.seonyakServer.domain.member.service.MemberService; -import org.sopt.seonyakServer.global.common.dto.ResponseDto; import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -30,11 +29,11 @@ public ResponseEntity login( } @PostMapping("/nickname") - public ResponseDto validNickname( + public ResponseEntity validNickname( @RequestBody final NicknameRequest nicknameRequest ) { memberService.validNickname(nicknameRequest); - return ResponseDto.success(null); + return ResponseEntity.ok().build(); } }