- Notifications
You must be signed in to change notification settings - Fork928
feat: Implement unified pagination and add template versions support#1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
475dcf9
01a52d1
d1478a9
7a36610
61c60c6
62fa273
878d633
5c840fd
07e590c
be8ba6c
5ab9ad5
e2a3741
61410a5
8a67746
55028d2
ea2371e
66af4ec
067f912
b8be7a8
13fc406
aab400c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package coderd | ||
import ( | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"github.com/google/uuid" | ||
"github.com/coder/coder/coderd/httpapi" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
// parsePagination extracts pagination query params from the http request. | ||
// If an error is encountered, the error is written to w and ok is set to false. | ||
func parsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Pagination, ok bool) { | ||
var ( | ||
afterID = uuid.Nil | ||
limit = -1 // Default to no limit and return all results. | ||
offset = 0 | ||
) | ||
var err error | ||
if s := r.URL.Query().Get("after_id"); s != "" { | ||
afterID, err = uuid.Parse(r.URL.Query().Get("after_id")) | ||
if err != nil { | ||
httpapi.Write(w, http.StatusBadRequest, httpapi.Response{ | ||
Message: fmt.Sprintf("after_id must be a valid uuid: %s", err.Error()), | ||
}) | ||
return p, false | ||
} | ||
} | ||
if s := r.URL.Query().Get("limit"); s != "" { | ||
limit, err = strconv.Atoi(s) | ||
if err != nil { | ||
httpapi.Write(w, http.StatusBadRequest, httpapi.Response{ | ||
Message: fmt.Sprintf("limit must be an integer: %s", err.Error()), | ||
}) | ||
return p, false | ||
} | ||
} | ||
if s := r.URL.Query().Get("offset"); s != "" { | ||
offset, err = strconv.Atoi(s) | ||
if err != nil { | ||
httpapi.Write(w, http.StatusBadRequest, httpapi.Response{ | ||
Message: fmt.Sprintf("offset must be an integer: %s", err.Error()), | ||
}) | ||
return p, false | ||
} | ||
} | ||
return codersdk.Pagination{ | ||
AfterID: afterID, | ||
Limit: limit, | ||
Offset: offset, | ||
}, true | ||
} |
Uh oh!
There was an error while loading.Please reload this page.