From 7ff2aef7facdeb025a1651ef411fceb3d81932c1 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 3 Feb 2017 15:17:34 -0500 Subject: Implement GET /users endpoint for APIv4 (#5277) --- api4/params.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'api4/params.go') diff --git a/api4/params.go b/api4/params.go index 452b9ba21..1c0c153ea 100644 --- a/api4/params.go +++ b/api4/params.go @@ -5,10 +5,17 @@ package api4 import ( "net/http" + "strconv" "github.com/gorilla/mux" ) +const ( + PAGE_DEFAULT = 0 + PER_PAGE_DEFAULT = 60 + PER_PAGE_MAXIMUM = 200 +) + type ApiParams struct { UserId string TeamId string @@ -18,6 +25,8 @@ type ApiParams struct { CommandId string HookId string EmojiId string + Page int + PerPage int } func ApiParamsFromRequest(r *http.Request) *ApiParams { @@ -57,5 +66,19 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams { params.EmojiId = val } + if val, err := strconv.Atoi(r.URL.Query().Get("page")); err != nil { + params.Page = PAGE_DEFAULT + } else { + params.Page = val + } + + if val, err := strconv.Atoi(r.URL.Query().Get("per_page")); err != nil { + params.PerPage = PER_PAGE_DEFAULT + } else if val > PER_PAGE_MAXIMUM { + params.PerPage = PER_PAGE_MAXIMUM + } else { + params.PerPage = val + } + return params } -- cgit v1.2.3-1-g7c22