From 414399fa506a2ff88d810279c69ef7195955309d Mon Sep 17 00:00:00 2001 From: Sin Ye Rin <91180366+nyeroni@users.noreply.github.com> Date: Fri, 1 Nov 2024 20:44:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=B2=B4=ED=81=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberApiController.java | 11 ++++++++ .../member/dto/NicknameDuplicateResponse.java | 11 ++++++++ .../wedle/member/service/MemberService.java | 26 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/main/java/yerong/wedle/member/dto/NicknameDuplicateResponse.java diff --git a/src/main/java/yerong/wedle/member/controller/MemberApiController.java b/src/main/java/yerong/wedle/member/controller/MemberApiController.java index b7765e5..c61174d 100644 --- a/src/main/java/yerong/wedle/member/controller/MemberApiController.java +++ b/src/main/java/yerong/wedle/member/controller/MemberApiController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import yerong.wedle.department.dto.DepartmentResponse; import yerong.wedle.department.service.DepartmentService; +import yerong.wedle.member.dto.NicknameDuplicateResponse; import yerong.wedle.member.dto.NicknameRequest; import yerong.wedle.member.dto.NicknameResponse; import yerong.wedle.member.service.MemberService; @@ -47,6 +48,16 @@ public ResponseEntity updateNickname(@RequestBody NicknameRequ return ResponseEntity.ok(memberService.setNickname(nicknameRequest)); } + @Operation(summary = "닉네임 중복 체크", description = "닉네임의 중복 여부를 확인합니다") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "닉네임 중복 확인 성공") + }) + @GetMapping("/nickname/check") + public ResponseEntity checkNicknameDuplicate(@RequestParam String nickname) { + NicknameDuplicateResponse nicknameDuplicateResponse = memberService.checkNicknameDuplicate(nickname); + return ResponseEntity.ok(nicknameDuplicateResponse); + } + @GetMapping("/nickname") public ResponseEntity getNickname() { return ResponseEntity.ok(memberService.getNickname()); diff --git a/src/main/java/yerong/wedle/member/dto/NicknameDuplicateResponse.java b/src/main/java/yerong/wedle/member/dto/NicknameDuplicateResponse.java new file mode 100644 index 0000000..e036169 --- /dev/null +++ b/src/main/java/yerong/wedle/member/dto/NicknameDuplicateResponse.java @@ -0,0 +1,11 @@ +package yerong.wedle.member.dto; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class NicknameDuplicateResponse { + private final boolean isDuplicate; + private final String message; +} diff --git a/src/main/java/yerong/wedle/member/service/MemberService.java b/src/main/java/yerong/wedle/member/service/MemberService.java index 15a8e16..0c6c677 100644 --- a/src/main/java/yerong/wedle/member/service/MemberService.java +++ b/src/main/java/yerong/wedle/member/service/MemberService.java @@ -4,6 +4,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import yerong.wedle.member.domain.Member; +import yerong.wedle.member.dto.NicknameDuplicateResponse; import yerong.wedle.member.dto.NicknameRequest; import yerong.wedle.member.dto.NicknameResponse; import yerong.wedle.member.exception.ExistingNicknameException; @@ -56,4 +57,29 @@ private String getCurrentUserId() { return socialId; } + + public NicknameDuplicateResponse checkNicknameDuplicate(String nickname) { + String socialId = getCurrentUserId(); + Member member = memberRepository.findBySocialId(socialId) + .orElseThrow(MemberNotFoundException::new); + + String message = ""; + boolean isDuplicate = false; + + if (member.getNickname() != null && member.getNickname().equals(nickname)) { + message = "기존 닉네임과 동일합니다."; + isDuplicate = true; + } else if (isNicknameDuplicate(nickname)) { + message = "이미 존재하는 닉네임입니다."; + isDuplicate = true; + } else { + message = "사용 가능한 닉네임입니다."; + isDuplicate = false; + } + + return NicknameDuplicateResponse.builder() + .isDuplicate(isDuplicate) + .message(message) + .build(); + } }