Pagination and filer by ID for GET /tokens
This commit is contained in:
parent
9be90df7bd
commit
c078e20ac5
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
@ -160,7 +161,12 @@ type tokenResponse struct {
|
||||||
|
|
||||||
// TokenGET retrieves a list listing all the user's public tokens.
|
// TokenGET retrieves a list listing all the user's public tokens.
|
||||||
func TokenGET(md common.MethodData) common.CodeMessager {
|
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 {
|
if err != nil {
|
||||||
return Err500
|
return Err500
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user