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

✨ follow user #431

Open
wants to merge 24 commits into
base: be/dev
Choose a base branch
from
Open

✨ follow user #431

wants to merge 24 commits into from

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Dec 5, 2024

  1. 유저 프로필 조회 시, 팔로잉, 팔로워 수 반환하도록 수정
  2. 유저 팔로우 구현
  3. 유저 언팔로우 구현
  4. 본인 계정의 팔로워 삭제 구현
  5. 유저 삭제에 따른 UserFollow 정리(팔로우 데이터 삭제, 팔로워, 팔로잉 수 수정)

@github-actions github-actions bot added ✨ feature new feature BE Backend labels Dec 5, 2024
Copy link
Contributor Author

Overall Project 89.94% -0.57% 🍏
Files changed 89.82% 🍏

File Coverage
UserController.java 100% 🍏
UserFollowResponse.java 100% 🍏
UserFollowRequest.java 100% 🍏
ProfileResponse.java 100% 🍏
User.java 96.41% 🍏
UserService.java 90.04% -5.53% 🍏
UserFollow.java 90% -10% 🍏

Comment on lines 27 to 28
0,
0,
user.getUserFollowerCount(),
user.getUserFolloweeCount(),
Copy link
Contributor

Choose a reason for hiding this comment

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

팔로우 여부를 필드로 추가해야 하겠어요!

Copy link
Contributor

@hyxrxn hyxrxn left a comment

Choose a reason for hiding this comment

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

follower과 followee... 하다가 게슈탈트 붕괴현상 일어나지 않았는지 걱정되네요 ㅋㅋㅋㅋ
고생하셨습니닷
몇 가지 의견 남겼어요~~~

Comment on lines 43 to 49
@Column(nullable = false)
@ColumnDefault("0")
private long userFollowerCount;

@Column(nullable = false)
@ColumnDefault("0")
private long userFolloweeCount;
Copy link
Contributor

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"})})
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 35 to 37
public UserFollow(User follower, User followee) {
this(0L, follower, followee);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

followerfollowee가 같은지 확인하지 않아도 될까요?

Choose a reason for hiding this comment

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

좋네요. �유니크 키가 있긴 하지만 validate 함수를 만들어 검사하는것이 빠르게 예외를 발생시킬 방법인것 같아요

Copy link
Contributor

Choose a reason for hiding this comment

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

UserFollow에 동등성 검증 로직,
서비스에 팔로우 중복 여부 검증 로직 추가했습니다!

Comment on lines 139 to 148
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

생각해보니 유저가 탈퇴했을 때 좋아요 개수는 변하지 않지만 팔로우 개수는 변하는군요...!!!
다음 회의 때 이야기해보면 좋을 것 같아요

Choose a reason for hiding this comment

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

제가 보기에는 팔로우 수가 줄어드는게 맞는것 같아요. 👍
회의에서 이야기 해봅시다

Comment on lines 304 to 307
assertAll(
() -> assertThat(deletedUserFollower).isTrue(),
() -> assertThat(deletedUserFollowee).isTrue()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

위 코멘트랑 관련있는데 삭제시 팔로워/팔로이의 숫자가 변하는게 정책이라면 이를 함께 확인하지 않아도 될까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

팔로워/팔로이 숫자를 검증하는 테스트 코드 추가하였습니다!

Copy link

@HaiSeong HaiSeong left a comment

Choose a reason for hiding this comment

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

리뷰가 늦어졌네요.
폰드 고생했습니다.
몇가지 생각해볼것 적어봤습니다.

Comment on lines 152 to 155
@Transactional
public UserFollowResponse followUser(long followerId, long followeeId) {
User follower = userRepository.findById(followerId)
.orElseThrow(() -> new NotFoundException("팔로워 정보를 조회할 수 없습니다."));

Choose a reason for hiding this comment

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

서비스 메서드가 재사용 가능하게 잘 만들어진것 같아요.

Comment on lines 35 to 37
public UserFollow(User follower, User followee) {
this(0L, follower, followee);
}

Choose a reason for hiding this comment

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

좋네요. �유니크 키가 있긴 하지만 validate 함수를 만들어 검사하는것이 빠르게 예외를 발생시킬 방법인것 같아요

Comment on lines +10 to +14
Optional<UserFollow> findByFollowerIdAndFolloweeId(Long followerId, Long followeeId);

List<UserFollow> findAllByFollowerId(long followerId);

List<UserFollow> findAllByFolloweeId(long followeeId);

Choose a reason for hiding this comment

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

UserFollow 도 authorAble을 구현해야 할까요?
사용자가 차단 한 상황에 팔로우 목록에서 보여줄지 고민이 필요할것 같아요.

또는 차단 했을때 팔로우를 지울지도 고민이 필요해보여요. 이 부분은 정책 회의때 이야기 해봐야 할것 같네요.

Copy link
Contributor

Choose a reason for hiding this comment

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

팔로워 목록에서는 차단한 사용자를 제외할 수 있을 것 같은데
팔로잉 목록에서도 가능한지 얘기해보고 싶습니다😢

Copy link
Contributor

Choose a reason for hiding this comment

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

차단하면 당연히 팔로우 하는 사람 목록과 팔로우 받는 사람 목록에서 빠져야 된다고 생각합니다.
전 아예 지워버려야 하는 게 맞다고 봐요!
테이블에서도 지우고, 인원 카운트에서도 내리고요.

Comment on lines 139 to 148
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);
}

Choose a reason for hiding this comment

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

제가 보기에는 팔로우 수가 줄어드는게 맞는것 같아요. 👍
회의에서 이야기 해봅시다

Copy link
Contributor Author

Overall Project 89.05% -1.78% 🍏
Files changed 79.21% 🍏

File Coverage
UserController.java 100% 🍏
RecipeController.java 100% 🍏
UserFollowResponse.java 100% 🍏
UserFollowRequest.java 100% 🍏
ProfileResponse.java 100% 🍏
User.java 96.41% 🍏
UserService.java 89.41% -6.36% 🍏
RecipeService.java 89.1% 🍏
UserFollow.java 31.03% -68.97% 🍏

Copy link
Contributor Author

Overall Project 89.15% -1.69% 🍏
Files changed 80.37% 🍏

File Coverage
UserController.java 100% 🍏
RecipeController.java 100% 🍏
UserFollowResponse.java 100% 🍏
UserFollowRequest.java 100% 🍏
ProfileResponse.java 100% 🍏
User.java 96.41% 🍏
UserService.java 89.41% -6.36% 🍏
RecipeService.java 89.1% 🍏
UserFollow.java 36.78% -63.22% 🍏

Copy link
Contributor Author

Overall Project 89.15% -1.69% 🍏
Files changed 80.37% 🍏

File Coverage
UserController.java 100% 🍏
RecipeController.java 100% 🍏
UserFollowResponse.java 100% 🍏
UserFollowRequest.java 100% 🍏
ProfileResponse.java 100% 🍏
User.java 96.41% 🍏
UserService.java 89.41% -6.36% 🍏
RecipeService.java 89.1% 🍏
UserFollow.java 36.78% -63.22% 🍏

Copy link
Contributor Author

github-actions bot commented Jan 6, 2025

Overall Project 89.54% -1.38% 🍏
Files changed 85.97% 🍏

File Coverage
UserController.java 100% 🍏
RecipeController.java 100% 🍏
UserFollowResponse.java 100% 🍏
UserFollowRequest.java 100% 🍏
FollowInfoResponse.java 100% 🍏
ProfileResponse.java 100% 🍏
FollowUserInfoResponse.java 100% 🍏
User.java 96.41% 🍏
UserService.java 92.74% -3.11% 🍏
RecipeService.java 87.52% 🍏
UserFollow.java 36.78% -63.22% 🍏

Comment on lines +184 to +194
@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);
}
Copy link

@HaiSeong HaiSeong Jan 7, 2025

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가 분리되면 좋겠습니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

동의합니다~~~~~
회의 때 따로 받을 수 있도록 하기로 정해졌으니 잊지 말고 요기도 수정 부탁해요~~~

Copy link
Contributor

@hyxrxn hyxrxn left a comment

Choose a reason for hiding this comment

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

팔로우 하나로 해야 할 기능이 참 많네요,,,,
조금만 더 화이팅 합시다~~~

Comment on lines +158 to +161
List<Recipe> recipes = recipeRepository.findAllByAuthorIdIn(
followeeIds,
pageRecipeRequest.getPageable()
);
Copy link
Contributor

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()
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

UserController에서는 왜 클래스단에 RequestMapping이 안묶여있죠???
그냥 궁금증...

Copy link
Contributor

Choose a reason for hiding this comment

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

이거 제가 차단목록 조회 하면서 묶을게욥

Choose a reason for hiding this comment

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

UserController에서는 왜 클래스단에 RequestMapping이 안묶여있죠???
그냥 궁금증...

그러게요 예전에 제가 작업한거긴한데 부탁드려요.

Comment on lines 39 to 47
@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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

이거 두개가 나눠져있는게 편한지 악어에게 물어봅시다
굳이 두개일 필요가 있을까 싶어서요~~~

Comment on lines +184 to +194
@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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

동의합니다~~~~~
회의 때 따로 받을 수 있도록 하기로 정해졌으니 잊지 말고 요기도 수정 부탁해요~~~

Comment on lines +10 to +14
Optional<UserFollow> findByFollowerIdAndFolloweeId(Long followerId, Long followeeId);

List<UserFollow> findAllByFollowerId(long followerId);

List<UserFollow> findAllByFolloweeId(long followeeId);
Copy link
Contributor

Choose a reason for hiding this comment

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

차단하면 당연히 팔로우 하는 사람 목록과 팔로우 받는 사람 목록에서 빠져야 된다고 생각합니다.
전 아예 지워버려야 하는 게 맞다고 봐요!
테이블에서도 지우고, 인원 카운트에서도 내리고요.

Copy link

@HaiSeong HaiSeong left a 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")

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) {

Choose a reason for hiding this comment

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

@PathVariable long userId 이거 컨벤션 확인해봐도 좋을것 같아요.
지금까지 저희가 Long 으로 사용했던것 같은데 확인 해봅시다.

Choose a reason for hiding this comment

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

아니면 지금까지 제가 잘못쓰고 있었을 수도 있어요. 다른분들은 어떻게 사용해오셨나요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE Backend ✨ feature new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants