Files
hfb_sys/backend/internal/modules/pickup/handler_parse.go
T

73 lines
1.4 KiB
Go

package pickup
import (
"strconv"
"hfb_sys/backend/internal/middleware"
"hfb_sys/backend/pkg/response"
"github.com/gin-gonic/gin"
)
func currentAdminID(c *gin.Context) (uint64, bool) {
value, ok := c.Get(middleware.ContextAdminID)
if !ok {
return 0, false
}
adminID, ok := value.(uint64)
return adminID, ok
}
func currentUserID(c *gin.Context) (uint64, bool) {
value, ok := c.Get(middleware.ContextUserID)
if !ok {
return 0, false
}
userID, ok := value.(uint64)
return userID, ok
}
func parseID(c *gin.Context) (uint64, bool) {
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil || id == 0 {
response.BadRequest(c, "ID 不正确")
return 0, false
}
return id, true
}
func parsePagination(c *gin.Context) (int, int) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = 20
}
if pageSize > 100 {
pageSize = 100
}
return page, pageSize
}
func parseAdminQuery(c *gin.Context) AdminPickupQuery {
page, pageSize := parsePagination(c)
return AdminPickupQuery{
Page: page,
PageSize: pageSize,
Keyword: c.Query("keyword"),
Status: c.Query("status"),
ShopName: c.Query("shop_name"),
}
}
func parseSellerQuery(c *gin.Context) SellerPickupQuery {
page, pageSize := parsePagination(c)
return SellerPickupQuery{
Page: page,
PageSize: pageSize,
Status: c.Query("status"),
}
}