-
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
Changes from all commits
650cd90
f3b4963
6d279bc
445864c
56d5e0a
f9df833
d9751a5
d92c465
f2618a4
1d45b50
517f013
6ccf1a5
9e6adc5
c3b879f
a415d5d
7da55bf
828d714
bf8a555
1e5bab0
8411209
578ffb2
8d4edb0
00195da
05d9f95
ebfb72c
d798b4f
472f323
1a12a2e
dcab263
3ecc31d
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import lombok.RequiredArgsConstructor; | ||
import net.pengcook.authentication.domain.UserInfo; | ||
import net.pengcook.authentication.resolver.LoginUser; | ||
import net.pengcook.user.dto.FollowInfoResponse; | ||
import net.pengcook.user.dto.ProfileResponse; | ||
import net.pengcook.user.dto.ReportReasonResponse; | ||
import net.pengcook.user.dto.ReportRequest; | ||
|
@@ -14,7 +15,10 @@ | |
import net.pengcook.user.dto.UpdateProfileResponse; | ||
import net.pengcook.user.dto.UserBlockRequest; | ||
import net.pengcook.user.dto.UserBlockResponse; | ||
import net.pengcook.user.dto.UserFollowRequest; | ||
import net.pengcook.user.dto.UserFollowResponse; | ||
import net.pengcook.user.dto.UsernameCheckResponse; | ||
import net.pengcook.user.service.UserFollowService; | ||
import net.pengcook.user.service.UserService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
|
@@ -32,15 +36,16 @@ | |
public class UserController { | ||
|
||
private final UserService userService; | ||
private final UserFollowService userFollowService; | ||
|
||
@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); | ||
} | ||
|
||
@PatchMapping("/user/me") | ||
|
@@ -84,4 +89,41 @@ 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
그러게요 예전에 제가 작업한거긴한데 부탁드려요. |
||
@ResponseStatus(HttpStatus.CREATED) | ||
public UserFollowResponse followUser( | ||
@LoginUser UserInfo userInfo, | ||
@RequestBody @Valid UserFollowRequest userFollowRequest | ||
) { | ||
return userFollowService.followUser(userInfo.getId(), userFollowRequest.targetId()); | ||
} | ||
|
||
@DeleteMapping("/user/follow") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public void unfollowUser( | ||
@LoginUser UserInfo userInfo, | ||
@RequestBody @Valid UserFollowRequest userFollowRequest | ||
) { | ||
userFollowService.unfollowUser(userInfo.getId(), userFollowRequest.targetId()); | ||
} | ||
|
||
@DeleteMapping("/user/follower") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public void removeFollower( | ||
@LoginUser UserInfo userInfo, | ||
@RequestBody @Valid UserFollowRequest userFollowRequest | ||
) { | ||
userFollowService.unfollowUser(userFollowRequest.targetId(), userInfo.getId()); | ||
} | ||
|
||
@GetMapping("/user/{userId}/follower") | ||
public FollowInfoResponse getFollowerInfo(@PathVariable long userId) { | ||
return userFollowService.getFollowerInfo(userId); | ||
} | ||
|
||
@GetMapping("/user/{userId}/following") | ||
public FollowInfoResponse getFollowingInfo(@PathVariable long userId) { | ||
return userFollowService.getFollowingInfo(userId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.pengcook.user.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.UniqueConstraint; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import net.pengcook.user.exception.BadArgumentException; | ||
|
||
@Entity | ||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"follower_id", "followee_id"})}) | ||
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. 👍 |
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(of = "id") | ||
@Getter | ||
public class UserFollow { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "follower_id") | ||
private User follower; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "followee_id") | ||
private User followee; | ||
|
||
public UserFollow(User follower, User followee) { | ||
validate(follower, followee); | ||
this.follower = follower; | ||
this.followee = followee; | ||
} | ||
|
||
private void validate(User follower, User followee) { | ||
if (follower.equals(followee)) { | ||
throw new BadArgumentException("자기 자신을 팔로우할 수 없습니다."); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.pengcook.user.dto; | ||
|
||
import java.util.List; | ||
|
||
public record FollowInfoResponse( | ||
List<FollowUserInfoResponse> follows, | ||
long followCount | ||
) { | ||
public FollowInfoResponse(List<FollowUserInfoResponse> follows) { | ||
this(follows, follows.size()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.pengcook.user.dto; | ||
|
||
import net.pengcook.user.domain.User; | ||
|
||
public record FollowUserInfoResponse(String username, String image) { | ||
|
||
public FollowUserInfoResponse(User user) { | ||
this(user.getUsername(), user.getImage()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.pengcook.user.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record UserFollowRequest(@NotNull long targetId) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.pengcook.user.dto; | ||
|
||
import net.pengcook.user.domain.UserFollow; | ||
|
||
public record UserFollowResponse( | ||
long followerId, | ||
long followeeId | ||
) { | ||
public UserFollowResponse(UserFollow userFollow) { | ||
this( | ||
userFollow.getFollower().getId(), | ||
userFollow.getFollowee().getId() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.pengcook.user.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class IllegalStateException extends UserException { | ||
|
||
public IllegalStateException(String message) { | ||
super(HttpStatus.FORBIDDEN, message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.pengcook.user.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import net.pengcook.user.domain.UserFollow; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserFollowRepository extends JpaRepository<UserFollow, Long> { | ||
|
||
Optional<UserFollow> findByFollowerIdAndFolloweeId(Long followerId, Long followeeId); | ||
|
||
List<UserFollow> findAllByFollowerId(long followerId); | ||
|
||
List<UserFollow> findAllByFolloweeId(long followeeId); | ||
Comment on lines
+10
to
+14
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.
또는 차단 했을때 팔로우를 지울지도 고민이 필요해보여요. 이 부분은 정책 회의때 이야기 해봐야 할것 같네요. 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. 팔로워 목록에서는 차단한 사용자를 제외할 수 있을 것 같은데 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. 차단하면 당연히 팔로우 하는 사람 목록과 팔로우 받는 사람 목록에서 빠져야 된다고 생각합니다. 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. 차단하면 실제 |
||
|
||
boolean existsByFollowerIdAndFolloweeId(long followerId, 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.
이거 두개가 나눠져있는게 편한지 악어에게 물어봅시다
굳이 두개일 필요가 있을까 싶어서요~~~