Files
online-backend/internal/backup/http.go
GuwandykA 28509eb4ca
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled
Add backups, currencies and dashboard APIs, and scope access by guard_name.
Web users may only CRUD their own records, operators stay in assigned branches, and admin/manager/superadmin keep full access.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-31 18:14:47 +05:00

82 lines
1.3 KiB
Go

package backup
import (
"strconv"
"strings"
"github.com/gin-gonic/gin"
)
const (
defaultPage = 1
defaultLimit = 10
maxLimit = 100
)
func parseID(raw string) (int64, bool) {
id, err := strconv.ParseInt(raw, 10, 64)
if err != nil || id <= 0 {
return 0, false
}
return id, true
}
func queryValue(c *gin.Context, keys ...string) string {
for _, key := range keys {
if raw := strings.TrimSpace(c.Query(key)); raw != "" && raw != "undefined" && raw != "null" {
return raw
}
}
return ""
}
func parsePageLimit(c *gin.Context) (page, limit int, ok bool) {
page = defaultPage
limit = defaultLimit
if raw := queryValue(c, "page"); raw != "" {
p, err := strconv.Atoi(raw)
if err != nil || p < 1 {
return 0, 0, false
}
page = p
}
if raw := queryValue(c, "limit"); raw != "" {
l, err := strconv.Atoi(raw)
if err != nil || l < 1 {
return 0, 0, false
}
if l > maxLimit {
l = maxLimit
}
limit = l
}
return page, limit, true
}
func currentUserID(c *gin.Context) *int64 {
rawID, exists := c.Get("id")
if !exists {
return nil
}
switch id := rawID.(type) {
case int64:
if id > 0 {
return &id
}
case int:
if id > 0 {
v := int64(id)
return &v
}
case string:
parsed, err := strconv.ParseInt(id, 10, 64)
if err == nil && parsed > 0 {
return &parsed
}
}
return nil
}