-
Notifications
You must be signed in to change notification settings - Fork 0
[BE] 회원 수정 가능 관련 수정 및 회원 로그아웃 기능 재구현 #306
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
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 |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| package com.jishop.member.dto.request; | ||
|
|
||
| import com.jishop.member.domain.User; | ||
|
|
||
| public record UserAdEmailRequest( | ||
| boolean adEmailAgree | ||
| ) { | ||
| public void update(User user){ | ||
| user.updateAdEmailAgree(adEmailAgree); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| package com.jishop.member.dto.request; | ||
|
|
||
| import com.jishop.member.domain.User; | ||
|
|
||
| public record UserAdSMSRequest( | ||
| boolean adSMSAgree | ||
| ) { | ||
| public void update(User user){ | ||
| user.updateAdSMSAgree(adSMSAgree); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package com.jishop.member.dto.request; | ||
|
|
||
| import com.jishop.member.domain.User; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record UserNameRequest( | ||
| @NotBlank | ||
| String name | ||
| ) { | ||
| public void update(User user){ | ||
| user.updateName(name); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package com.jishop.member.dto.request; | ||
|
|
||
| import com.jishop.member.domain.User; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record UserPhoneRequest( | ||
| @NotBlank | ||
| String phone | ||
| ) { | ||
| public void update(User user){ | ||
| user.updatePhone(phone); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.function.Consumer; | ||
|
|
||
| @Service | ||
| @Transactional | ||
|
|
@@ -67,13 +68,15 @@ public boolean checkPW(RecoveryPWRequest request){ | |
| } | ||
|
|
||
| public void updatePW(User user, UserNewPasswordRequest request){ | ||
|
Contributor
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. 아래에 사용자 정보 업데이트 메서드들이 동일한 패턴을 반복하고 있는데 패턴을 추상화해서 중복을 제거하는것 어떻게 생각하시나요?
Contributor
Author
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. 업데이트에 대한 각각의 구현체로 만들라는 말씀이실까요오??
Contributor
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. 밑의 코드들이
public void update메서드 (User user, UserRequest request) {
Contributor
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. 진호님 말 처럼 개별적으로 수정이 들어가는데 개별적으로 로직 처리가 있어서 개별적인 메소드 처리라면 방법이 떠오르진 않지만
Contributor
Author
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. 지금 현재 피그마 상으로 각각 개별적으로 수정이 이루어져 해당 수정시마다 개별적인 컨트롤러가 호출 되고 있습니다 중복되는 코드에 대해선 개선하고 알려드리겠습니다!
Contributor
Author
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. 개선 완료 했습니다! |
||
| if(passwordEncoder.matches(request.password(), user.getPassword())){ | ||
| User persistUser = getPersistUser(user); | ||
|
|
||
| if(passwordEncoder.matches(request.password(), persistUser.getPassword())){ | ||
| throw new DomainException(ErrorType.PASSWORD_EXISTS); | ||
| } | ||
|
|
||
| String password = passwordEncoder.encode(request.password()); | ||
| user.updatePassword(password); | ||
| updateUserCache(user); | ||
| persistUser.updatePassword(password); | ||
| updateUserCache(persistUser); | ||
| } | ||
|
|
||
| // todo: 회원 정보 조회 | ||
|
|
@@ -83,38 +86,53 @@ public UserResponse getUser(User user){ | |
|
|
||
| // todo: 회원 정보 수정 (이름, 전화번호) | ||
| public void updateUserName(User user, UserNameRequest request) { | ||
| user.updateName(request.name()); | ||
| updateUserCache(user); | ||
| applyAndCache(user, request::update); | ||
| } | ||
|
|
||
| public void updatePhone(User user, UserPhoneRequest request) { | ||
| user.updatePhone(request.phone()); | ||
| updateUserCache(user); | ||
| applyAndCache(user, request::update); | ||
| } | ||
|
|
||
| public void deleteUser(User user) { | ||
| user.delete(); | ||
| User persistUser = getPersistUser(user); | ||
| persistUser.delete(); | ||
| } | ||
|
|
||
| public Long checkLogin(User user) { | ||
| return user.getId(); | ||
| } | ||
|
|
||
| public void updateAdSMSAgree(User user, UserAdSMSRequest request){ | ||
| user.updateAdSMSAgree(request.adSMSAgree()); | ||
| updateUserCache(user); | ||
| applyAndCache(user, request::update); | ||
| } | ||
|
|
||
| public void updateAdEmailAgree(User user, UserAdEmailRequest request){ | ||
| user.updateAdEmailAgree(request.adEmailAgree()); | ||
| updateUserCache(user); | ||
| applyAndCache(user, request::update); | ||
| } | ||
|
|
||
| private void updateUserCache(User user) { | ||
| String cacheKey = "user::" + user.getId(); | ||
|
|
||
| // 캐시 업데이트 (기존 캐시 삭제 후 최신 정보로 재설정) | ||
| redisTemplate.delete(cacheKey); | ||
| redisTemplate.opsForValue().set(cacheKey, user, Duration.ofMinutes(30)); | ||
| } | ||
|
|
||
| private User getPersistUser(User user){ | ||
|
Contributor
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. 이 메소드를 userRepository 쪽으로 옮기면 어떨까요?
Contributor
Author
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. 해당 메서드를 userRepository에 옮긴다는게 무슨 말인지 잘 모르겠습니다... 구체적인 예시를 알려주실수 있으실까요,,?🥲
Contributor
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. userRepository에 default 메소드로 빼면 좋을 것같아요
Contributor
Author
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. 별 차이가 없다고 느껴집니다 왜 default 메서드로 빼면 좋을지! 설명 부탁드립니다!
Contributor
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. 다른 곳에서도 유저를 사용해서 레포지토리에 있다면 반복 코드를 쓰지 않을 것 같아서 입니다.
Contributor
Author
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. 해당 부분은 @currentuser로 인해 다른 도메인의 서비스 로직에서 User를 직접 조회해서 사용하는 경우는 없다고 생각했습니다!
Contributor
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. 사용할 것 같습니다.! 추후에 내 자신이 아닌 다른 사용자를 확인 할때 필요할 수 도 있을 것 같습니다. |
||
| User persistUser = userRepository.findPersistUser(user); | ||
|
|
||
| return persistUser; | ||
| } | ||
|
|
||
| private void applyAndCache(User user, Consumer<User> update) { | ||
| User persistUser = getPersistUser(user); | ||
| update.accept(persistUser); | ||
| updateUserCache(persistUser); | ||
| } | ||
|
|
||
| public void logout(User user) { | ||
| String cacheKey = "user::" + user.getId(); | ||
| redisTemplate.delete(cacheKey); | ||
| } | ||
| } | ||
|
|
||
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.
회원 정보 수정 기능을 개선하는데, 로그아웃 요청 시에
HttpServletRequest가 아닌User로 수정하는 것과 어떤 연관이 있나요?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.
기존 로그아웃은 해당 회원의 세션만 삭제해서 로그인 여부를 판단했습니다 하지만 CurrentUser를 이용해 redis에 사용자를 캐싱하게되므로써 캐싱된 회원 객체도 삭제시켜줘야한다는 필요성이 생겼습니다 그래서 서비스 로직에서 redis에 저장된 해당 회원객체를 삭제해야했습니다!
추후 인가부분의 재정리가 필요해 정리할 예정입니다!