ListFollowers returns a list of users that are following the given user. Results are paginated by given page and page size, and sorted by the time of follow in descending order.
(ctx context.Context, userID int64, page, pageSize int)
| 815 | // Results are paginated by given page and page size, and sorted by the time of |
| 816 | // follow in descending order. |
| 817 | func (s *UsersStore) ListFollowers(ctx context.Context, userID int64, page, pageSize int) ([]*User, error) { |
| 818 | /* |
| 819 | Equivalent SQL for PostgreSQL: |
| 820 | |
| 821 | SELECT * FROM "user" |
| 822 | LEFT JOIN follow ON follow.user_id = "user".id |
| 823 | WHERE follow.follow_id = @userID |
| 824 | ORDER BY follow.id DESC |
| 825 | LIMIT @limit OFFSET @offset |
| 826 | */ |
| 827 | users := make([]*User, 0, pageSize) |
| 828 | return users, s.db.WithContext(ctx). |
| 829 | Joins(dbutil.Quote("LEFT JOIN follow ON follow.user_id = %s.id", "user")). |
| 830 | Where("follow.follow_id = ?", userID). |
| 831 | Limit(pageSize).Offset((page - 1) * pageSize). |
| 832 | Order("follow.id DESC"). |
| 833 | Find(&users). |
| 834 | Error |
| 835 | } |
| 836 | |
| 837 | // ListFollowings returns a list of users that are followed by the given user. |
| 838 | // Results are paginated by given page and page size, and sorted by the time of |