ch some
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -78,7 +79,7 @@ func (h *handler) list(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /activity-logs/{id} [get]
|
||||
func (h *handler) getByID(c *gin.Context) {
|
||||
id, ok := parseID(c.Param("id"))
|
||||
id, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
// GET /activity-logs/card-orders → list that module instead of 400.
|
||||
q := c.Request.URL.Query()
|
||||
@@ -104,24 +105,10 @@ func (h *handler) getByID(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(item))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, true
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPage = 1
|
||||
defaultLimit = 10
|
||||
maxLimit = 100
|
||||
)
|
||||
|
||||
func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
filter := ListFilter{
|
||||
Page: defaultPage,
|
||||
Limit: defaultLimit,
|
||||
Page: shared.DefaultPage,
|
||||
Limit: shared.DefaultLimit,
|
||||
}
|
||||
|
||||
if id, ok := optionalQueryID(c, "user_id", "userId"); !ok {
|
||||
@@ -146,8 +133,8 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
if err != nil || limit < 1 {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
if limit > maxLimit {
|
||||
limit = maxLimit
|
||||
if limit > shared.MaxLimit {
|
||||
limit = shared.MaxLimit
|
||||
}
|
||||
filter.Limit = limit
|
||||
}
|
||||
@@ -169,7 +156,7 @@ func optionalQueryID(c *gin.Context, keys ...string) (*int64, bool) {
|
||||
if raw == "" {
|
||||
return nil, true
|
||||
}
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user