Skip to content

Commit

Permalink
Merge pull request BAEKDODAM#20 from LinaKK/feat/member
Browse files Browse the repository at this point in the history
Feat/member
  • Loading branch information
LinaKK authored Mar 12, 2024
2 parents a5174ad + 9b9c916 commit b9fd3c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/main/java/com/ImageTrip/exception/GlobalExceptionAdvice.java
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/ImageTrip/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,22 @@ 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);

}



public void verifyExistsEmail(String email) {
Optional<Member> 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<Member> optionalMember = memberRepository.findByEmail(name);
if(optionalMember.isPresent()) new BusinessLogicException(ExceptionCode.MEMBER_EXISTS);
Optional<Member> optionalMember = memberRepository.findByName(name);
if(optionalMember.isPresent()) throw new BusinessLogicException(ExceptionCode.MEMBER_EXISTS);

}

Expand Down

0 comments on commit b9fd3c8

Please sign in to comment.