-
Notifications
You must be signed in to change notification settings - Fork 10
강수빈 2주차 과제 #4
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
base: main
Are you sure you want to change the base?
강수빈 2주차 과제 #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,11 +52,14 @@ public AuthLoginResponse signUp(AuthSignUpRequest request) { | |
// TODO : 로그인을 진행한다. | ||
public AuthLoginResponse login(AuthLoginRequest request) { | ||
// DB에서 memberLoginId와 memberPassword를 조회하여 일치하는 회원이 있는지 확인한다. | ||
|
||
Member member = memberRepository.findByMemberLoginIdAndMemberPassword( request.getMemberLoginId(), request.getMemberPassword() ); | ||
// 만약 일치하는 회원이 없다면, IllegalArgumentException을 발생시킨다. | ||
|
||
if(member == null) { | ||
throw new IllegalArgumentException("일치하는 회원이 없거등요 다시 입력해~"); | ||
} | ||
// 일치하는 회원이 있다면, MemberResponse로 변환하여 반환한다. | ||
return null; | ||
// 이건 좀 어렵네요...답지를 참고했습니다 자동생성으로 알려주긴 한데 없었으면 못 썼을 거 같습니다.... | ||
return AuthLoginResponse.from(member); | ||
} | ||
Comment on lines
+61
to
63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 부분은 원래 안 익숙해서 그러실 수 있습니다!! |
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,26 +31,48 @@ public MemberResponse findOneMember(Long memberId) { | |
// TODO : 전체 회원 정보를 조회한다. | ||
public List<MemberResponse> findAllMembers() { | ||
// DB에서 전체 회원 정보를 조회한다. | ||
|
||
List<Member> member = memberRepository.findAll(); | ||
// 조회된 회원 정보를 List<MemberResponse>로 변환하여 반환한다. | ||
return null; | ||
// 얘도 답지 없었으면 못 구현했음........... | ||
return member.stream() | ||
.map(MemberResponse::from) | ||
.toList(); | ||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 답지 보더라도 구현해내시느라 고생하셨씁니다 ㅎㅎ.. |
||
} | ||
|
||
// TODO : 회원 이름으로 회원 정보를 조회한다. | ||
public List<MemberResponse> searchMembersWithName(String memberName) { | ||
// DB에서 memberName에 해당하는 회원 정보를 조회한다. | ||
|
||
List<Member> member = memberRepository.findByMemberName(memberName); | ||
// 조회된 회원 정보를 List<MemberResponse>로 변환하여 반환한다. | ||
return null; | ||
return member.stream() | ||
.map(MemberResponse::from) | ||
.toList(); | ||
} | ||
|
||
// TODO : 회원 비밀번호를 변경한다. | ||
public void changePassword(Long memberId, AuthPasswordChangeRequest request) { | ||
// DB에서 memberId에 해당하는 회원 정보를 조회하고, 존재하지 않는다면 IllegalArgumentException을 발생시킨다. | ||
|
||
// Member member = memberRepository.findById(memberId); | ||
// if (member.isEmpty()) { | ||
// throw new IllegalArgumentException("존재 안함 ㅠㅠ"); | ||
// } | ||
// 이렇게 쓰면 되는데 왜 위처럼 쓰면 안되지ㅣ.. | ||
Comment on lines
+55
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JpaRepository에서 findById는 기본적으로 Optional이라는 형태로 나오게 됩니다. 이 클래스는 isEmpty() 등의 메소드를 가지고 있어서 주석처럼 사용될 수 있습니다. 하지만 Member 클래스는 기본 클래스로 isEmpty() 메소드를 갖고 있지 않습니다! |
||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 회원입니다.")); | ||
// 조회된 회원 정보의 비밀번호를 변경한다. ( request.getNewPassword()를 이용하여 변경한다. ) | ||
|
||
// 오... 이렇게... | ||
member.changePassword(request.getOldPassword(), request.getNewPassword()); | ||
// 변경된 회원 정보를 DB에 저장한다. | ||
memberRepository.save(member); | ||
} | ||
|
||
public void deleteMember(Long memberId) { | ||
Optional<Member> member = memberRepository.findById(memberId); | ||
if (member.isEmpty()) { | ||
throw new IllegalArgumentException("존재하지 않는 회원입니다."); | ||
} | ||
else{ | ||
memberRepository.deleteById(memberId); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete Method 사용해주시는 부분 RESTful하게 좋습니다.
저도 종종 delete 관련 메소드 짤 때, 아래처럼 짜기도 하는데 아래처럼 짜면 api 형식이 깔끔해져서 좋더라구요. 참고해보시면 좋을 것 같습니다.