forked from mtusi2026/mtusi2026lab7
на оценку 4
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"mtusi2026lab7/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
|
||||
}
|
||||
Reference in New Issue
Block a user