Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from f-lab-edu/feature/15
Browse files Browse the repository at this point in the history
#16 #30 feature/15
  • Loading branch information
yyy9942 committed Nov 28, 2019
2 parents 5e3c4c2 + fa9dd1f commit 5095183
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 496 deletions.
150 changes: 20 additions & 130 deletions src/main/java/com/delfood/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.delfood.aop.MemberLoginCheck;
import com.delfood.dto.MemberDTO;
import com.delfood.error.exception.DuplicateIdException;
import com.delfood.service.MemberService;
import com.delfood.utils.SessionUtil;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -65,11 +66,10 @@ public class MemberController {
*/
@GetMapping("myInfo")
@MemberLoginCheck
public ResponseEntity<MemberInfoResponse> memberInfo(HttpSession session) {
public MemberInfoResponse memberInfo(HttpSession session) {
String id = SessionUtil.getLoginMemberId(session);
MemberDTO memberInfo = memberService.getMemberInfo(id);
return new ResponseEntity<MemberInfoResponse>(new MemberInfoResponse(memberInfo),
HttpStatus.OK);
return new MemberInfoResponse(memberInfo);
}

/**
Expand All @@ -79,21 +79,10 @@ public ResponseEntity<MemberInfoResponse> memberInfo(HttpSession session) {
* @param id 중복체크를 진행할 고객 아이디
* @return
*/
@GetMapping("idCheck/{id}")
public ResponseEntity<MemberIdDuplResponse> idCheck(@PathVariable @NotNull String id) {
ResponseEntity<MemberIdDuplResponse> responseEntity = null;
MemberIdDuplResponse duplResponse;
@GetMapping("duplicated/{id}")
public boolean idCheck(@PathVariable @NotNull String id) {
boolean idDuplicated = memberService.isDuplicatedId(id);
if (idDuplicated) {
// 아이디가 중복되어있을 때
duplResponse = MemberIdDuplResponse.DUPLICATED;
responseEntity = new ResponseEntity<>(duplResponse, HttpStatus.CONFLICT);
} else {
// 아이디가 중복되어있지 않을 때
duplResponse = MemberIdDuplResponse.SUCCESS;
responseEntity = new ResponseEntity<>(duplResponse, HttpStatus.OK);
}
return responseEntity;
return idDuplicated;
}

/*
Expand All @@ -109,25 +98,12 @@ public ResponseEntity<MemberIdDuplResponse> idCheck(@PathVariable @NotNull Strin
*
*/
@PostMapping
public ResponseEntity<SignUpResponse> signUp(@RequestBody @NotNull MemberDTO memberInfo) {
ResponseEntity<SignUpResponse> responseEntity = null;
SignUpResponse result;
@ResponseStatus(HttpStatus.CREATED)
public void signUp(@RequestBody @NotNull MemberDTO memberInfo) {
if (MemberDTO.hasNullDataBeforeSignup(memberInfo)) {
throw new NullPointerException("회원가입시 필수 데이터를 모두 입력해야 합니다.");
}
String id = memberInfo.getId();
boolean idDuplicated = memberService.isDuplicatedId(id);
if (idDuplicated) {
// 중복 아이디일 때
result = SignUpResponse.ID_DUPLICATED;
responseEntity = new ResponseEntity<SignUpResponse>(result, HttpStatus.CONFLICT);
} else {
// 중복 아이디가 아닐 때
memberService.insertMember(memberInfo);
result = SignUpResponse.SUCCESS;
responseEntity = new ResponseEntity<SignUpResponse>(result, HttpStatus.CREATED);
}
return responseEntity;
memberService.insertMember(memberInfo);
}

/**
Expand All @@ -152,10 +128,6 @@ public ResponseEntity<LoginResponse> login(@RequestBody @NonNull MemberLoginRequ
loginResponse = LoginResponse.success(memberInfo);
SessionUtil.setLoginMemberId(session, id);
responseEntity = new ResponseEntity<LoginResponse>(loginResponse, HttpStatus.OK);
} else if (MemberDTO.Status.DELETED.equals(memberInfo.getStatus())) {
// 삭제된 경우
loginResponse = LoginResponse.DELETED;
responseEntity = new ResponseEntity<LoginResponse>(loginResponse, HttpStatus.UNAUTHORIZED);
} else {
// 예상하지 못한 오류일 경우
log.error("login ERROR" + responseEntity);
Expand All @@ -174,41 +146,29 @@ public ResponseEntity<LoginResponse> login(@RequestBody @NonNull MemberLoginRequ
*/
@GetMapping("logout")
@MemberLoginCheck
@ResponseStatus(code = HttpStatus.OK)
public void logout(HttpSession session) {
SessionUtil.logoutMember(session);
}

/**
* 회원 비밀번호 변경.
*
* 원래 비밀번호, 변경할 비밀번호를 모두 입력해야 한다.
* 변경 전 비밀번호가 일치하지 않을 시 비밀번호가 변경되지 않는다.
* @param session 현재 로그인한 사용자의 세션
* @return
*/
@PatchMapping("password")
@MemberLoginCheck
public ResponseEntity<UpdateMemberPasswordResponse> updateMemberInfo(HttpSession session,
public void updateMemberInfo(HttpSession session,
@RequestBody @NotNull UpdateMemberPasswordRequest passwordRequest) {
String password = passwordRequest.getPassword();
String newPassword = passwordRequest.getNewPassword();
String passwordBeforeChange = passwordRequest.getPasswordBeforeChange();
String passwordAfterChange = passwordRequest.getPasswordAfterChange();
String id = SessionUtil.getLoginMemberId(session);
ResponseEntity<UpdateMemberPasswordResponse> responseEntity = null;
if (memberService.login(id, password) == null) {
// 원래 패스워드가 일치하지 않음
responseEntity = new ResponseEntity<UpdateMemberPasswordResponse>(
UpdateMemberPasswordResponse.PASSWORD_MISMATCH, HttpStatus.UNAUTHORIZED);
} else if (newPassword == null) {
// 새로운 패스워드를 입력하지 않음
responseEntity = new ResponseEntity<UpdateMemberPasswordResponse>(
UpdateMemberPasswordResponse.EMPTY_PASSWORD, HttpStatus.BAD_REQUEST);
if (passwordAfterChange == null || passwordBeforeChange == null) { // 유효성 검사
throw new NullPointerException("패스워드를 입력해주세요");
} else {
// 성공시
memberService.updateMemberPassword(id, newPassword);
responseEntity =
new ResponseEntity<MemberController.UpdateMemberPasswordResponse>(HttpStatus.OK);
memberService.updateMemberPassword(id, passwordBeforeChange, passwordAfterChange);
}

return responseEntity;
}

/**
Expand All @@ -220,12 +180,11 @@ public ResponseEntity<UpdateMemberPasswordResponse> updateMemberInfo(HttpSession
*/
@DeleteMapping("myInfo")
@MemberLoginCheck
@ResponseStatus(code = HttpStatus.OK)
public void deleteMemberInfo(HttpSession session) {
String id = SessionUtil.getLoginMemberId(session);
memberService.deleteMember(id);
// 회원 탈퇴시 로그아웃 시켜야 하기 때문에 세션 정보를 날린다
SessionUtil.clear(session);
SessionUtil.logoutMember(session);
}

/**
Expand Down Expand Up @@ -278,83 +237,14 @@ enum LoginStatus {
private MemberDTO memberInfo;

// success의 경우 memberInfo의 값을 set해줘야 하기 때문에 new 하도록 해준다.

private static final LoginResponse FAIL = new LoginResponse(LoginStatus.FAIL);
private static final LoginResponse DELETED = new LoginResponse(LoginStatus.DELETED);

private static LoginResponse success(MemberDTO memberInfo) {
return new LoginResponse(LoginStatus.SUCCESS, memberInfo);
}


}

@Getter
@RequiredArgsConstructor
private static class LogoutResponse {
// 해당 클래스는 AOP 적용으로 통합되었습니다.
// 추후 확장성을 고려하여 클래스를 남겨놓습니다 - jun
}

@Getter
@RequiredArgsConstructor
private static class SignUpResponse {
enum SignUpStatus {
SUCCESS, ID_DUPLICATED, ERROR, NULL_ARGUMENT
}

@NonNull
private SignUpStatus result;

private static final SignUpResponse SUCCESS = new SignUpResponse(SignUpStatus.SUCCESS);
private static final SignUpResponse ID_DUPLICATED =
new SignUpResponse(SignUpStatus.ID_DUPLICATED);
}

@Getter
@RequiredArgsConstructor
private static class MemberIdDuplResponse {
enum DuplStatus {
SUCCESS, ID_DUPLICATED, ERROR
}

@NonNull
private DuplStatus result;

private static final MemberIdDuplResponse SUCCESS =
new MemberIdDuplResponse(DuplStatus.SUCCESS);
private static final MemberIdDuplResponse DUPLICATED =
new MemberIdDuplResponse(DuplStatus.ID_DUPLICATED);


}

@Getter
private static class UpdateMemberPasswordResponse {
enum Message {
EMPTY_PASSWORD, PASSWORD_MISMATCH
}

@NonNull
private Message message;

private static final UpdateMemberPasswordResponse EMPTY_PASSWORD =
new UpdateMemberPasswordResponse(Message.EMPTY_PASSWORD);
private static final UpdateMemberPasswordResponse PASSWORD_MISMATCH =
new UpdateMemberPasswordResponse(Message.PASSWORD_MISMATCH);

public UpdateMemberPasswordResponse(Message message) {
this.message = message;
}
}

@Getter
@RequiredArgsConstructor
private static class DeleteMemberResponse {
// 해당 메서드는 AOP로 통합되었습니다.
// 추후 확장성을 고려하여 남겨놓습니다 - jun
}

@Getter
private static class UpdateMemberAddressResponse {
enum UpdateStatus {
Expand Down Expand Up @@ -386,9 +276,9 @@ private static class MemberInfoResponse {
@Getter
private static class UpdateMemberPasswordRequest {
@NonNull
private String password;
private String passwordBeforeChange;
@NonNull
private String newPassword;
private String passwordAfterChange;
}

@Setter
Expand Down
Loading

0 comments on commit 5095183

Please sign in to comment.