diff options
author | Joe Chen <jc@unknwon.io> | 2022-10-23 16:17:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-23 16:17:53 +0800 |
commit | b1fefcbe5011a4a792808faaf26fae6881ecc1b0 (patch) | |
tree | 42c3d2922ea8460f6f5bf1ebb314039275c25ec2 /internal/route/api/v1/user | |
parent | 8077360cf6370c9ddb026f2432ceb4f4f4ac31c4 (diff) |
refactor(db): migrate `Follow` off `user.go` (#7203)
Diffstat (limited to 'internal/route/api/v1/user')
-rw-r--r-- | internal/route/api/v1/user/follower.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/internal/route/api/v1/user/follower.go b/internal/route/api/v1/user/follower.go index c587547b..d21c6029 100644 --- a/internal/route/api/v1/user/follower.go +++ b/internal/route/api/v1/user/follower.go @@ -20,9 +20,9 @@ func responseApiUsers(c *context.APIContext, users []*db.User) { } func listUserFollowers(c *context.APIContext, u *db.User) { - users, err := u.GetFollowers(c.QueryInt("page")) + users, err := db.Users.ListFollowers(c.Req.Context(), u.ID, c.QueryInt("page"), db.ItemsPerPage) if err != nil { - c.Error(err, "get followers") + c.Error(err, "list followers") return } responseApiUsers(c, users) @@ -41,9 +41,9 @@ func ListFollowers(c *context.APIContext) { } func listUserFollowing(c *context.APIContext, u *db.User) { - users, err := u.GetFollowing(c.QueryInt("page")) + users, err := db.Users.ListFollowings(c.Req.Context(), u.ID, c.QueryInt("page"), db.ItemsPerPage) if err != nil { - c.Error(err, "get following") + c.Error(err, "list followings") return } responseApiUsers(c, users) @@ -62,7 +62,7 @@ func ListFollowing(c *context.APIContext) { } func checkUserFollowing(c *context.APIContext, u *db.User, followID int64) { - if u.IsFollowing(followID) { + if db.Follows.IsFollowing(c.Req.Context(), u.ID, followID) { c.NoContent() } else { c.NotFound() @@ -94,7 +94,7 @@ func Follow(c *context.APIContext) { if c.Written() { return } - if err := db.FollowUser(c.User.ID, target.ID); err != nil { + if err := db.Follows.Follow(c.Req.Context(), c.User.ID, target.ID); err != nil { c.Error(err, "follow user") return } @@ -106,7 +106,7 @@ func Unfollow(c *context.APIContext) { if c.Written() { return } - if err := db.UnfollowUser(c.User.ID, target.ID); err != nil { + if err := db.Follows.Unfollow(c.Req.Context(), c.User.ID, target.ID); err != nil { c.Error(err, "unfollow user") return } |