This commit is contained in:
toom1996
2026-09-13 00:52:35 +08:00
parent 10d8a96e8c
commit dbee704c95
44 changed files with 755 additions and 1148 deletions

View File

@ -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),
})
}