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

feature/4-update-1 #10

Merged
merged 26 commits into from
Feb 28, 2022
Merged

feature/4-update-1 #10

merged 26 commits into from
Feb 28, 2022

Conversation

jiae5287
Copy link
Collaborator

@jiae5287 jiae5287 commented Feb 17, 2022

<구현한 기능>

  1. 패스워드 변경
  2. 주소 저장하기
  3. 모든 주소 가져오기
  4. 주소 삭제하기
  5. 주소 수정하기

<구현할 기능>
session.

  • 최근 주소 가져오기 기능은 추가할지 말지 좀 더 생각해볼 계획입니다.



@ResponseStatus(code = HttpStatus.OK)
@PatchMapping("/myAccount/password")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path에 대문자가 들어가는건 그다지 좋지 않습니다.
url에 들어가는 문자에 제한이 있는데, 한 번 찾아보시면 좋을 것 같네요 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다. my-account로 바꿨습니다.

Comment on lines 46 to 57
public User changePassword(Long id, String encryptedPassword) {
User currentUser = this.findById(id);
User changedUser = new User(
currentUser.getId(),
currentUser.getEmail(),
encryptedPassword,
currentUser.getName(),
currentUser.getPhoneNumber()
);
hashmap.replace(id, changedUser);
return changedUser;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 repository에서 해야 할 일일까요?
Repository가 어떤건지 한 번 다시 찾아보시는게 필요할 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제했습니다. repository에 대해 다시 찾아봤습니다.

@@ -8,4 +8,6 @@
User findById(Long id);

User findByEmail(String email);

User changePassword(Long id, String encryptedPassword);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository의 역할에 changePassword가 들어가는게 적합할까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제했습니다.

// *** 아이디를 session에서 꺼내고 사용할 예정 *** session.getId();
// *** session을 이용한다면 일치하는 사용자가 있는지 확인하지 않아도 되겠지..? :: 67~8번째줄
//User user = userRepository.findById(session.getId());
User user = userRepository.findById(1L);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findById에는 command로부터 들어온 패스워드를 변경할 User의 id를 넣어줘야 되겠네요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

임시로 넣어뒀던거라ㅎㅎ 지금은 user의 id값으로 수정했습니다.

@@ -54,4 +55,25 @@ public UserResult signin(SigninCommand signinCommand) {
}
return UserResult.fromUser(user);
}

@Override
public UserResult updatePassword(PasswordUpdateCommand passwordUpdateCommand) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PasswordUpdateCommand 객체에는 userId가 없는데, 어떤 유저의 비밀번호를 변경하는지 어떻게 알 수 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatePassword() 코드 전체 수정했습니다.

Comment on lines 62 to 64
// *** 아이디를 session에서 꺼내고 사용할 예정 *** session.getId();
// *** session을 이용한다면 일치하는 사용자가 있는지 확인하지 않아도 되겠지..? :: 67~8번째줄
//User user = userRepository.findById(session.getId());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

세션을 Service에서 직접 사용하는게 바람직한 방법일까요?
session은 어떤 레이어에서 가져야 할 책임일까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service에서 사용하지는 않았고 controller에서 가져왔습니다. :)
session값을 가져와야 한다는 뜻이었습니다ㅎㅎ

@jiae5287 jiae5287 changed the title 비밀번호 수정 기능 구현 중 비밀번호 수정 기능, 주소 받기 기능 만듦 Feb 24, 2022
@jiae5287 jiae5287 changed the title 비밀번호 수정 기능, 주소 받기 기능 만듦 비밀번호 수정 기능, 주소 받기 기능 구현 중 Feb 24, 2022
@jiae5287 jiae5287 changed the title 비밀번호 수정 기능, 주소 받기 기능 구현 중 feature/4-update-1 Feb 26, 2022
throw new PasswordIsNotMatchException("현재 패스워드가 일치하지 않습니다.");
}
User result = userRepository.save(
new User(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새 User 객체를 만들 필요가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사실 setter를 사용하고 싶었는데,
도메인일 경우 setter를 사용하기보단 새로운 객체를 생성하는 것이 더 안전하다는 글을 읽었습니다.
setter와 new를 사용하지 않고 안전하게 코드를 바꾸는 방법이 있을까요? 지금은 setter밖에 생각이 안 나서요ㅎㅎ;;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새 객체를 생성하는게 왜 더 안전한가요?
객체가 상태를 유지 관리 하는 객체라면 새 객체를 생성하면 상태가 사라져서 의도와 다른 동작을 하게 될 수 있습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇군요!ㅎㅎ 그런 경우엔 새로운 객체를 생성하는 것보다 setter가 훨씬 좋겠네요 :)
저는 setter를 쓰면 안된다는 강박 같은게 있었는데 잘못 생각했네요ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setXXX 대신 변경을 의미적으로 더 잘 드러낼 수 있는 메소드를 정의할 수 있다며 더 좋습니다.
setPassword -> changePassword 로 하고 내부에서 필요한 다른 검증이나 처리들을 더 해줄 수도 있겠죠 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경했습니다. 비밀번호 암호화를 changePassword에서 하고 싶어서 encryptMapper를 매개변수로 넘겨줬습니다.
시간 되실 때 괜찮은 방법인지 한번 확인해주세요 :)

@@ -1,5 +1,7 @@
package com.happy.delivery.domain.user;

import com.happy.delivery.infra.encoder.EncryptMapper;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain에서 infra의 의존성을 바로 가지는건 좋지 않을 것 같네요.
패스워드를 암호화 하는게 도메인의 역할이라 생각된다면 domain에서 패스워드를 암호화하는 인터페이스를 구현해두고, infra에서 구현한 뒤 주입받아서 사용하여야 될 것 같네요.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 추후에 리펙토링 하면서 의존성 고민을 해보시면 좋겠네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 좀 더 고민해보겠습니다.

Copy link
Collaborator

@f-lab-bright f-lab-bright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

throw new PasswordIsNotMatchException("현재 패스워드가 일치하지 않습니다.");
}
user.changePassword(encryptMapper, passwordUpdateCommand.getChangedPassword());
User result = userRepository.save(user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update에서는 다시 할당 받지 않아도 되긴 합니다.
다시 받더라도 결국 같은 주소의 인스턴스가 반환될거라 대부분은요 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아! 그렇네요ㅎㅎ 수정하겠습니다.

@@ -1,5 +1,7 @@
package com.happy.delivery.domain.user;

import com.happy.delivery.infra.encoder.EncryptMapper;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 추후에 리펙토링 하면서 의존성 고민을 해보시면 좋겠네요

@jiae5287 jiae5287 merged commit c691c07 into main Feb 28, 2022
@jiae5287 jiae5287 linked an issue Feb 28, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[#1] 로그인 로그아웃 외 부가 정보 서비스 개발
3 participants