-
Notifications
You must be signed in to change notification settings - Fork 0
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
✨ follow user #431
base: be/dev
Are you sure you want to change the base?
✨ follow user #431
Conversation
github-actions
bot
commented
Dec 5, 2024
•
edited by tackyu
Loading
edited by tackyu
- 유저 프로필 조회 시, 팔로잉, 팔로워 수 반환하도록 수정
- 유저 팔로우 구현
- 유저 언팔로우 구현
- 본인 계정의 팔로워 삭제 구현
- 유저 삭제에 따른 UserFollow 정리(팔로우 데이터 삭제, 팔로워, 팔로잉 수 수정)
|
0, | ||
0, | ||
user.getUserFollowerCount(), | ||
user.getUserFolloweeCount(), |
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.
팔로우 여부를 필드로 추가해야 하겠어요!
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.
follower과 followee... 하다가 게슈탈트 붕괴현상 일어나지 않았는지 걱정되네요 ㅋㅋㅋㅋ
고생하셨습니닷
몇 가지 의견 남겼어요~~~
@Column(nullable = false) | ||
@ColumnDefault("0") | ||
private long userFollowerCount; | ||
|
||
@Column(nullable = false) | ||
@ColumnDefault("0") | ||
private long userFolloweeCount; |
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.
변수명 앞에 user는 빼도 되지 않을까요???
+) 저희 DB 수정도 필요하겠네요....!!
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"follower_id", "followee_id"})}) |
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.
👍
public UserFollow(User follower, User followee) { | ||
this(0L, follower, followee); | ||
} |
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.
follower
와 followee
가 같은지 확인하지 않아도 될까요?
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.
좋네요. �유니크 키가 있긴 하지만 validate 함수를 만들어 검사하는것이 빠르게 예외를 발생시킬 방법인것 같아요
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.
UserFollow에 동등성 검증 로직,
서비스에 팔로우 중복 여부 검증 로직 추가했습니다!
List<UserFollow> followings = userFollowRepository.findAllByFollowerId(userInfo.getId()); | ||
for (UserFollow userFollow : followings) { | ||
userFollow.getFollowee().decreaseUserFollowerCount(); | ||
userFollowRepository.delete(userFollow); | ||
} | ||
List<UserFollow> followers = userFollowRepository.findAllByFolloweeId(userInfo.getId()); | ||
for (UserFollow userFollow : followers) { | ||
userFollow.getFollower().decreaseUserFolloweeCount(); | ||
userFollowRepository.delete(userFollow); | ||
} |
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.
생각해보니 유저가 탈퇴했을 때 좋아요 개수는 변하지 않지만 팔로우 개수는 변하는군요...!!!
다음 회의 때 이야기해보면 좋을 것 같아요
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.
제가 보기에는 팔로우 수가 줄어드는게 맞는것 같아요. 👍
회의에서 이야기 해봅시다
assertAll( | ||
() -> assertThat(deletedUserFollower).isTrue(), | ||
() -> assertThat(deletedUserFollowee).isTrue() | ||
); |
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.
위 코멘트랑 관련있는데 삭제시 팔로워/팔로이의 숫자가 변하는게 정책이라면 이를 함께 확인하지 않아도 될까요?
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.
팔로워/팔로이 숫자를 검증하는 테스트 코드 추가하였습니다!
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.
리뷰가 늦어졌네요.
폰드 고생했습니다.
몇가지 생각해볼것 적어봤습니다.
@Transactional | ||
public UserFollowResponse followUser(long followerId, long followeeId) { | ||
User follower = userRepository.findById(followerId) | ||
.orElseThrow(() -> new NotFoundException("팔로워 정보를 조회할 수 없습니다.")); |
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.
서비스 메서드가 재사용 가능하게 잘 만들어진것 같아요.
public UserFollow(User follower, User followee) { | ||
this(0L, follower, followee); | ||
} |
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.
좋네요. �유니크 키가 있긴 하지만 validate 함수를 만들어 검사하는것이 빠르게 예외를 발생시킬 방법인것 같아요
Optional<UserFollow> findByFollowerIdAndFolloweeId(Long followerId, Long followeeId); | ||
|
||
List<UserFollow> findAllByFollowerId(long followerId); | ||
|
||
List<UserFollow> findAllByFolloweeId(long followeeId); |
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.
UserFollow
도 authorAble을 구현해야 할까요?
사용자가 차단 한 상황에 팔로우 목록에서 보여줄지 고민이 필요할것 같아요.
또는 차단 했을때 팔로우를 지울지도 고민이 필요해보여요. 이 부분은 정책 회의때 이야기 해봐야 할것 같네요.
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.
팔로워 목록에서는 차단한 사용자를 제외할 수 있을 것 같은데
팔로잉 목록에서도 가능한지 얘기해보고 싶습니다😢
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.
차단하면 당연히 팔로우 하는 사람 목록과 팔로우 받는 사람 목록에서 빠져야 된다고 생각합니다.
전 아예 지워버려야 하는 게 맞다고 봐요!
테이블에서도 지우고, 인원 카운트에서도 내리고요.
List<UserFollow> followings = userFollowRepository.findAllByFollowerId(userInfo.getId()); | ||
for (UserFollow userFollow : followings) { | ||
userFollow.getFollowee().decreaseUserFollowerCount(); | ||
userFollowRepository.delete(userFollow); | ||
} | ||
List<UserFollow> followers = userFollowRepository.findAllByFolloweeId(userInfo.getId()); | ||
for (UserFollow userFollow : followers) { | ||
userFollow.getFollower().decreaseUserFolloweeCount(); | ||
userFollowRepository.delete(userFollow); | ||
} |
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.
제가 보기에는 팔로우 수가 줄어드는게 맞는것 같아요. 👍
회의에서 이야기 해봅시다
|
|
|
|
@Transactional(readOnly = true) | ||
public FollowInfoResponse getFollowInfo(long userId) { | ||
List<FollowUserInfoResponse> followers = userFollowRepository.findAllByFolloweeId(userId).stream() | ||
.map(userFollow -> new FollowUserInfoResponse(userFollow.getFollower())) | ||
.toList(); | ||
List<FollowUserInfoResponse> followings = userFollowRepository.findAllByFollowerId(userId).stream() | ||
.map(userFollow -> new FollowUserInfoResponse(userFollow.getFollowee())) | ||
.toList(); | ||
|
||
return new FollowInfoResponse(followers, followings); | ||
} |
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.
ui 디자인상에서 Follow / Following 정보를 같이 주니 api를 한번에 전송하도록 설계하신것 같아요!
개인적으로 api가 ui에 영향을 받으면 안좋다고 생각합니다!
추후에 정보를 따로 받을때도 사용 가능하게 api가 분리되면 좋겠습니다!
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.
동의합니다~~~~~
회의 때 따로 받을 수 있도록 하기로 정해졌으니 잊지 말고 요기도 수정 부탁해요~~~
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.
팔로우 하나로 해야 할 기능이 참 많네요,,,,
조금만 더 화이팅 합시다~~~
List<Recipe> recipes = recipeRepository.findAllByAuthorIdIn( | ||
followeeIds, | ||
pageRecipeRequest.getPageable() | ||
); |
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.
이거 한 줄로 해도 되지 않을까용
.map(Recipe::getId) | ||
.toList(); | ||
|
||
return recipeRepository.findRecipeDataV1(recipeIds).stream() |
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.
이거 생각해보니까 findRecipeDataV1
에서 찾아오는게 다 레시피 정보들이네요.
이 메서드 자체가 필요가 없는 거 같아요...
RecipeHomeResponse
도 마찬가지고요...
이 dto랑 이 메서드를 왜 만들었죠....????!
없어도 되는 애들을 안 불러오기 위해서인가....?????
그냥 도메인(레시피)으로 찾아와도 될 거 같은데, 다음 회의 때 이야기해보아요...!!
아무튼 이 부분에서는 굳이 레파지토리를 두 번 들릴 필요 없을 거 같아요!
이미 위에서 레시피 정보를 다 찾았으니 그 정보들로 바로 RecipeHomeWithMineResponseV1
로 변환할 방법을 찾는 게 어떨까요??
@@ -84,4 +87,36 @@ public UserBlockResponse blockUser( | |||
) { | |||
return userService.blockUser(userInfo.getId(), userBlockRequest.blockeeId()); | |||
} | |||
|
|||
@PostMapping("/user/follow") |
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.
UserController
에서는 왜 클래스단에 RequestMapping
이 안묶여있죠???
그냥 궁금증...
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.
이거 제가 차단목록 조회 하면서 묶을게욥
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.
UserController에서는 왜 클래스단에 RequestMapping이 안묶여있죠???
그냥 궁금증...
그러게요 예전에 제가 작업한거긴한데 부탁드려요.
@GetMapping("/user/me") | ||
public ProfileResponse getUserProfile(@LoginUser UserInfo userInfo) { | ||
return userService.getUserById(userInfo.getId()); | ||
return userService.getProfile(userInfo.getId(), userInfo.getId()); | ||
} | ||
|
||
@GetMapping("/user/{userId}") | ||
public ProfileResponse getUserProfile(@PathVariable long userId) { | ||
return userService.getUserById(userId); | ||
public ProfileResponse getUserProfile(@LoginUser UserInfo userInfo, @PathVariable long userId) { | ||
return userService.getProfile(userInfo.getId(), userId); | ||
} |
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.
이거 두개가 나눠져있는게 편한지 악어에게 물어봅시다
굳이 두개일 필요가 있을까 싶어서요~~~
@Transactional(readOnly = true) | ||
public FollowInfoResponse getFollowInfo(long userId) { | ||
List<FollowUserInfoResponse> followers = userFollowRepository.findAllByFolloweeId(userId).stream() | ||
.map(userFollow -> new FollowUserInfoResponse(userFollow.getFollower())) | ||
.toList(); | ||
List<FollowUserInfoResponse> followings = userFollowRepository.findAllByFollowerId(userId).stream() | ||
.map(userFollow -> new FollowUserInfoResponse(userFollow.getFollowee())) | ||
.toList(); | ||
|
||
return new FollowInfoResponse(followers, followings); | ||
} |
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.
동의합니다~~~~~
회의 때 따로 받을 수 있도록 하기로 정해졌으니 잊지 말고 요기도 수정 부탁해요~~~
Optional<UserFollow> findByFollowerIdAndFolloweeId(Long followerId, Long followeeId); | ||
|
||
List<UserFollow> findAllByFollowerId(long followerId); | ||
|
||
List<UserFollow> findAllByFolloweeId(long followeeId); |
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.
차단하면 당연히 팔로우 하는 사람 목록과 팔로우 받는 사람 목록에서 빠져야 된다고 생각합니다.
전 아예 지워버려야 하는 게 맞다고 봐요!
테이블에서도 지우고, 인원 카운트에서도 내리고요.
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.
폰드 리뷰가 늦었습니다. 수고하셨어요. 아토가 아직 RC 상태라 저도 Comment로 두겠습니다!
@@ -84,4 +87,36 @@ public UserBlockResponse blockUser( | |||
) { | |||
return userService.blockUser(userInfo.getId(), userBlockRequest.blockeeId()); | |||
} | |||
|
|||
@PostMapping("/user/follow") |
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.
UserController에서는 왜 클래스단에 RequestMapping이 안묶여있죠???
그냥 궁금증...
그러게요 예전에 제가 작업한거긴한데 부탁드려요.
} | ||
|
||
@GetMapping("/user/{userId}/follows") | ||
public FollowInfoResponse getFollowInfo(@PathVariable long userId) { |
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.
@PathVariable long userId
이거 컨벤션 확인해봐도 좋을것 같아요.
지금까지 저희가 Long 으로 사용했던것 같은데 확인 해봅시다.
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.
아니면 지금까지 제가 잘못쓰고 있었을 수도 있어요. 다른분들은 어떻게 사용해오셨나요?