Add start_index & limit to GetFollowersFollowing

This commit is contained in:
Marco Realacci 2022-11-22 15:27:05 +01:00
parent c134becb61
commit 77e9f405c6
3 changed files with 21 additions and 9 deletions

View file

@ -25,13 +25,21 @@ func (rt *_router) GetFollowersFollowing(w http.ResponseWriter, r *http.Request,
var err error
var status database.QueryResult
// Get limits, or use default values
start_index, limit, err := helpers.GetLimits(r.URL.Query())
if err != nil {
helpers.SendBadRequest(w, "Invalid start_index or limit", rt.baseLogger)
return
}
// Check if client is asking for followers or following
if strings.HasSuffix(r.URL.Path, "/followers") {
// Get the followers from the database
status, users, err = rt.db.GetUserFollowers(uid, ctx.Auth.GetUserID())
status, users, err = rt.db.GetUserFollowers(uid, ctx.Auth.GetUserID(), start_index, limit)
} else {
// Get the following users from the database
status, users, err = rt.db.GetUserFollowing(uid, ctx.Auth.GetUserID())
status, users, err = rt.db.GetUserFollowing(uid, ctx.Auth.GetUserID(), start_index, limit)
}
// Send a 500 response if there was an error