From c078e20ac51e4b7201463a30efb45889c6331d08 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 1 Jul 2017 21:37:25 +0200 Subject: [PATCH] Pagination and filer by ID for GET /tokens --- app/v1/token.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/v1/token.go b/app/v1/token.go index 8ddb502..1fb6a73 100644 --- a/app/v1/token.go +++ b/app/v1/token.go @@ -4,6 +4,7 @@ import ( "crypto/md5" "database/sql" "fmt" + "strconv" "time" "github.com/jmoiron/sqlx" @@ -160,7 +161,12 @@ type tokenResponse struct { // TokenGET retrieves a list listing all the user's public tokens. func TokenGET(md common.MethodData) common.CodeMessager { - rows, err := md.DB.Query("SELECT id, privileges, description, last_updated FROM tokens WHERE user = ? AND private = '0'", md.ID()) + wc := common.Where("user = ? AND private = 0", strconv.Itoa(md.ID())) + if md.Query("id") != "" { + wc.Where("id = ?", md.Query("id")) + } + rows, err := md.DB.Query("SELECT id, privileges, description, last_updated FROM tokens "+ + wc.Clause+common.Paginate(md.Query("p"), md.Query("l"), 50), wc.Params...) if err != nil { return Err500 }