ch9.2-9.3

This commit is contained in:
lbenedar
2026-03-18 16:31:33 +03:00
parent 985340c557
commit 17267ed145
6 changed files with 149 additions and 0 deletions

19
internal/data/filters.go Normal file
View File

@@ -0,0 +1,19 @@
package data
import "gitea.local.lab/Lbenedar/greenlight/internal/validator"
type Filters struct {
Page int
PageSize int
Sort string
SortSafelist []string
}
func ValidateFilters(v *validator.Validator, f Filters) {
v.Check(f.Page > 0, "page", "must be greater than zero")
v.Check(f.Page <= 10_000_000, "page", "must be a maximum of 10 million")
v.Check(f.PageSize > 0, "page_size", "must be greater than zero")
v.Check(f.PageSize <= 100, "page_size", "must be a maximum of 100")
v.Check(validator.PermittedValue(f.Sort, f.SortSafelist...), "sort", "invalid sort values")
}