Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/member #20

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading