update
This commit is contained in:
@ -2,17 +2,17 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"fashionapi/internal/dto"
|
||||
"fashionapi/internal/middleware"
|
||||
"fashionapi/internal/pkg/pagination"
|
||||
"fashionapi/internal/pkg/response"
|
||||
"fashionapi/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// HistoryHandler 浏览历史接口(需 Bearer 鉴权,挂在 /api/v1/auth 下)。
|
||||
// HistoryHandler 浏览历史接口(需 Bearer 鉴权,主挂载于 /api/v1/me,legacy /api/v1/auth 仅兼容旧前端)。
|
||||
type HistoryHandler struct {
|
||||
hist service.HistoryService
|
||||
}
|
||||
@ -32,15 +32,8 @@ func (h *HistoryHandler) List(c *gin.Context) {
|
||||
response.Error(c, http.StatusUnauthorized, "unauthorized")
|
||||
return
|
||||
}
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
perPage, _ := strconv.Atoi(c.DefaultQuery("per_page", "24"))
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if perPage < 1 || perPage > 100 {
|
||||
perPage = 24
|
||||
}
|
||||
items, total, err := h.hist.ListPaged(c.Request.Context(), userID, page, perPage)
|
||||
p := pagination.Parse(c, "page", "per_page", 1, 24, 100)
|
||||
items, total, err := h.hist.ListPaged(c.Request.Context(), userID, p.Page, p.PageSize)
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
@ -48,7 +41,7 @@ func (h *HistoryHandler) List(c *gin.Context) {
|
||||
response.Data(c, http.StatusOK, gin.H{
|
||||
"items": items,
|
||||
"total": total,
|
||||
"last_page": response.LastPage(total, perPage),
|
||||
"last_page": response.LastPage(total, p.PageSize),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user