feat: port lab4 implementation

This commit is contained in:
kk10
2026-11-13 15:52:39 +03:00
parent 276dbdad8a
commit 36d9b0c8f6
101 changed files with 8426 additions and 6 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
}