на оценку 5

This commit is contained in:
2026-11-10 16:21:46 +03:00
parent 276dbdad8a
commit 7110afc598
170 changed files with 21149 additions and 30 deletions
@@ -0,0 +1,29 @@
package handlers
import (
"net/http"
"strconv"
"mtusi2026lab5/internal/transport/http/response"
)
func parsePagination(w http.ResponseWriter, r *http.Request, requestID string) (int, string, bool) {
query := r.URL.Query()
limit := 50
if query.Has("limit") {
parsed, err := strconv.Atoi(query.Get("limit"))
if err != nil || parsed < 1 || parsed > 100 {
response.WriteError(w, http.StatusBadRequest, response.CodeInvalidRequest,
"limit must be an integer between 1 and 100", requestID)
return 0, "", false
}
limit = parsed
}
cursor := query.Get("cursor")
if query.Has("cursor") && cursor == "" {
response.WriteError(w, http.StatusBadRequest, response.CodeInvalidRequest,
"cursor must not be empty", requestID)
return 0, "", false
}
return limit, cursor, true
}