chore: port lab 1 solution

This commit is contained in:
kk10
2026-10-02 11:45:26 +03:00
parent 65003b6119
commit 2f279a1715
43 changed files with 2402 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package httpx
import (
"net/http"
"strconv"
"mtusi2026-messenger/internal/dto"
)
func ParsePagination(w http.ResponseWriter, r *http.Request, requestID string) (limit int, cursor *string, ok bool) {
q := r.URL.Query()
limit = 50
if raw := q.Get("limit"); raw != "" {
v, err := strconv.Atoi(raw)
if err != nil || v < 1 || v > 100 {
WriteError(
w,
http.StatusBadRequest,
dto.ErrorCodeInvalidRequest,
"limit must be an integer between 1 and 100",
requestID,
)
return 0, nil, false
}
limit = v
}
if raw := q.Get("cursor"); raw != "" {
cursor = &raw
}
return limit, cursor, true
}