Paginating Lists

This commit is contained in:
Maxime Delporte
2025-11-15 16:34:40 +01:00
parent fc2e401f6f
commit 6fc5e725e6
2 changed files with 16 additions and 2 deletions

View File

@@ -23,6 +23,14 @@ func ValidateFilters(v *validator.Validator, f Filters) {
v.Check(validator.PermittedValue(f.Sort, f.SortSafelist...), "sort", "invalid sort value")
}
func (f Filters) limit() int {
return f.PageSize
}
func (f Filters) offset() int {
return (f.Page - 1) * f.PageSize
}
// sortColumn : Check that the client-provided Sort field matches one of the entries in our safelist and if it does, extract the column name from the Sort field by stripping the leading hyphen character (if one exists)
func (f Filters) sortColumn() string {
for _, safeValue := range f.SortSafelist {