From f5d5a639362a7f018185292d3fcaa77792f9cfdf Mon Sep 17 00:00:00 2001 From: Kang Duoh Date: Sun, 3 Nov 2024 09:56:31 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=EC=B2=B4=ED=81=AC=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../momento/member/api/MemberController.java | 16 ++++++++++++++++ .../member/application/MemberService.java | 5 +++++ .../domain/repository/MemberRepository.java | 1 + 3 files changed, 22 insertions(+) diff --git a/src/main/java/com/hackathon/momento/member/api/MemberController.java b/src/main/java/com/hackathon/momento/member/api/MemberController.java index 3c1d5fb..2975bd1 100644 --- a/src/main/java/com/hackathon/momento/member/api/MemberController.java +++ b/src/main/java/com/hackathon/momento/member/api/MemberController.java @@ -14,6 +14,7 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -78,4 +79,19 @@ public RspTemplate updateProfile( ProfileResDto updatedProfile = memberService.updateProfile(principal, reqDto); return new RspTemplate<>(HttpStatus.OK, "프로필 수정 성공", updatedProfile); } + + @PostMapping("/check-duplicate") + @Operation( + summary = "이메일 중복 검사", + description = "해당 사용자가 존재하는지 여부를 검사합니다.", + responses = { + @ApiResponse(responseCode = "200", description = "중복 검사 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청"), + @ApiResponse(responseCode = "500", description = "서버 오류") + } + ) + public RspTemplate checkDuplicateRequest(Principal principal) { + boolean isDuplicate = memberService.checkDuplicate(principal); + return new RspTemplate<>(HttpStatus.OK, String.valueOf(isDuplicate)); + } } diff --git a/src/main/java/com/hackathon/momento/member/application/MemberService.java b/src/main/java/com/hackathon/momento/member/application/MemberService.java index fbda086..d400bbc 100644 --- a/src/main/java/com/hackathon/momento/member/application/MemberService.java +++ b/src/main/java/com/hackathon/momento/member/application/MemberService.java @@ -46,6 +46,11 @@ public ProfileResDto updateProfile(Principal principal, UpdateProfileReqDto reqD return ProfileResDto.from(member); } + public boolean checkDuplicate(Principal principal) { + Member member = getMemberByPrincipal(principal); + return memberRepository.existsById(member.getId()); + } + private Member getMemberByPrincipal(Principal principal) { Long memberId = Long.parseLong(principal.getName()); return memberRepository.findById(memberId) diff --git a/src/main/java/com/hackathon/momento/member/domain/repository/MemberRepository.java b/src/main/java/com/hackathon/momento/member/domain/repository/MemberRepository.java index 4412139..b9fd5fc 100644 --- a/src/main/java/com/hackathon/momento/member/domain/repository/MemberRepository.java +++ b/src/main/java/com/hackathon/momento/member/domain/repository/MemberRepository.java @@ -8,5 +8,6 @@ @Repository public interface MemberRepository extends JpaRepository { + Optional findByEmail(String email); }