From 4890607590b7729c8f066292f7af1be56d9533d4 Mon Sep 17 00:00:00 2001 From: LinaKK Date: Wed, 13 Mar 2024 01:28:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=EB=B3=84=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionAdvice.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ImageTrip/exception/GlobalExceptionAdvice.java b/src/main/java/com/ImageTrip/exception/GlobalExceptionAdvice.java index 3db68fb..9b1e670 100644 --- a/src/main/java/com/ImageTrip/exception/GlobalExceptionAdvice.java +++ b/src/main/java/com/ImageTrip/exception/GlobalExceptionAdvice.java @@ -1,2 +1,17 @@ -package com.ImageTrip.exception;public class GlobalExceptionAdvice { +package com.ImageTrip.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalExceptionAdvice { + + @ExceptionHandler + public ResponseEntity handleBusinessLogicException(BusinessLogicException e) { + String message = e.getMessage(); + + return new ResponseEntity<>(message, HttpStatus.valueOf(e.getExceptionCode().getStatus())); + } } From 9b9c916a9c5d12ad427c7a60cb710b083af252c4 Mon Sep 17 00:00:00 2001 From: LinaKK Date: Wed, 13 Mar 2024 01:40:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=ED=99=95=EC=9D=B8,=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=ED=99=95=EC=9D=B8=20=EB=AF=B8=EB=8F=99?= =?UTF-8?q?=EC=9E=91=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImageTrip/member/controller/MemberController.java | 2 +- .../java/com/ImageTrip/member/service/MemberService.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ImageTrip/member/controller/MemberController.java b/src/main/java/com/ImageTrip/member/controller/MemberController.java index 9d2b2a6..9b36501 100644 --- a/src/main/java/com/ImageTrip/member/controller/MemberController.java +++ b/src/main/java/com/ImageTrip/member/controller/MemberController.java @@ -34,7 +34,7 @@ public MemberController(MemberService memberService, @PostMapping("/checkUsableEmail") public ResponseEntity checkUseableEmail(@RequestBody @Valid MemberDto.CheckEmailDto checkEmailDto){ - memberService.verifyExistsName(checkEmailDto.getEmail()); + memberService.verifyExistsEmail(checkEmailDto.getEmail()); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/src/main/java/com/ImageTrip/member/service/MemberService.java b/src/main/java/com/ImageTrip/member/service/MemberService.java index 99bda98..2207a99 100644 --- a/src/main/java/com/ImageTrip/member/service/MemberService.java +++ b/src/main/java/com/ImageTrip/member/service/MemberService.java @@ -100,7 +100,7 @@ public void checkUserPassword(String token, String password) { Member member = findMemberByToken(token); if (!passwordEncoder.encode(password).equals(member.getPassword())) - new BusinessLogicException(ExceptionCode.UNMATCHED_PASSWORD); + throw new BusinessLogicException(ExceptionCode.UNMATCHED_PASSWORD); } @@ -108,13 +108,14 @@ public void checkUserPassword(String token, String password) { public void verifyExistsEmail(String email) { Optional optionalMember = memberRepository.findByEmail(email); - if(optionalMember.isPresent()) new BusinessLogicException(ExceptionCode.MEMBER_EXISTS); + System.out.println(optionalMember); + if(optionalMember.isPresent()) throw new BusinessLogicException(ExceptionCode.MEMBER_EXISTS); } public void verifyExistsName(String name) { - Optional optionalMember = memberRepository.findByEmail(name); - if(optionalMember.isPresent()) new BusinessLogicException(ExceptionCode.MEMBER_EXISTS); + Optional optionalMember = memberRepository.findByName(name); + if(optionalMember.isPresent()) throw new BusinessLogicException(ExceptionCode.MEMBER_EXISTS); }