Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-17 12:16:36 +03:00
parent f9728b8a4c
commit c6bdf83f05
4 changed files with 43 additions and 30 deletions

View File

@@ -35,14 +35,9 @@ func GetProductPricingListHandler(w http.ResponseWriter, r *http.Request) {
limit = parsed
}
}
offset := 0
if raw := strings.TrimSpace(r.URL.Query().Get("offset")); raw != "" {
if parsed, err := strconv.Atoi(raw); err == nil && parsed >= 0 && parsed <= 1000000 {
offset = parsed
}
}
afterProductCode := strings.TrimSpace(r.URL.Query().Get("after_product_code"))
rows, err := queries.GetProductPricingList(ctx, limit+1, offset)
rows, err := queries.GetProductPricingList(ctx, limit+1, afterProductCode)
if err != nil {
if isPricingTimeoutLike(err, ctx.Err()) {
log.Printf(
@@ -71,16 +66,21 @@ func GetProductPricingListHandler(w http.ResponseWriter, r *http.Request) {
if hasMore {
rows = rows[:limit]
}
nextCursor := ""
if hasMore && len(rows) > 0 {
nextCursor = strings.TrimSpace(rows[len(rows)-1].ProductCode)
}
log.Printf(
"[ProductPricing] trace=%s success user=%s id=%d limit=%d offset=%d count=%d has_more=%t duration_ms=%d",
"[ProductPricing] trace=%s success user=%s id=%d limit=%d after=%q count=%d has_more=%t next=%q duration_ms=%d",
traceID,
claims.Username,
claims.ID,
limit,
offset,
afterProductCode,
len(rows),
hasMore,
nextCursor,
time.Since(started).Milliseconds(),
)
@@ -90,6 +90,9 @@ func GetProductPricingListHandler(w http.ResponseWriter, r *http.Request) {
} else {
w.Header().Set("X-Has-More", "false")
}
if nextCursor != "" {
w.Header().Set("X-Next-Cursor", nextCursor)
}
_ = json.NewEncoder(w).Encode(rows)
}