From 0edbff13cda8f213b86c4791395d4fb95067ae2e Mon Sep 17 00:00:00 2001 From: Howl Date: Sun, 16 Oct 2016 16:45:42 +0200 Subject: [PATCH] Add sorting stuff to GET v1/friends --- app/v1/friend.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/v1/friend.go b/app/v1/friend.go index 6a0e950..02a901e 100644 --- a/app/v1/friend.go +++ b/app/v1/friend.go @@ -39,8 +39,7 @@ func FriendsGET(md common.MethodData) common.CodeMessager { md.Err(err) } - // Yes. - const myFriendsQuery = ` + myFriendsQuery := ` SELECT users.id, users.username, users.register_datetime, users.privileges, users.latest_activity, @@ -52,9 +51,19 @@ ON users_relationships.user2 = users.id LEFT JOIN users_stats ON users_relationships.user2=users_stats.id WHERE users_relationships.user1=? -ORDER BY users_relationships.id` +` - results, err := md.DB.Query(myFriendsQuery+common.Paginate(md.Query("p"), md.Query("l"), 50), md.ID()) + myFriendsQuery += common.Sort(md, common.SortConfiguration{ + Allowed: []string{ + "id", + "username", + "latest_activity", + }, + Default: "users.id asc", + Table: "users", + }) + "\n" + + results, err := md.DB.Query(myFriendsQuery+common.Paginate(md.Query("p"), md.Query("l"), 100), md.ID()) if err != nil { md.Err(err) return Err500