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"
|
||||
)
|
||||
|
||||
// FavoriteHandler 收藏接口(需 Bearer 鉴权,挂在 /api/v1/auth 下)。
|
||||
// FavoriteHandler 收藏接口(需 Bearer 鉴权,主挂载于 /api/v1/me,legacy /api/v1/auth 仅兼容旧前端)。
|
||||
type FavoriteHandler struct {
|
||||
favs service.FavoriteService
|
||||
}
|
||||
@ -33,20 +33,13 @@ func (h *FavoriteHandler) 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
|
||||
}
|
||||
p := pagination.Parse(c, "page", "per_page", 1, 24, 100)
|
||||
kind := c.Query("kind")
|
||||
if kind != "" && kind != dto.FavoriteKindGallery && kind != dto.FavoriteKindImage {
|
||||
response.Error(c, http.StatusBadRequest, "invalid kind")
|
||||
return
|
||||
}
|
||||
items, total, err := h.favs.ListPaged(c.Request.Context(), userID, page, perPage, kind)
|
||||
items, total, err := h.favs.ListPaged(c.Request.Context(), userID, p.Page, p.PageSize, kind)
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
@ -54,7 +47,7 @@ func (h *FavoriteHandler) 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),
|
||||
})
|
||||
}
|
||||
|
||||
@ -102,7 +95,7 @@ func (h *FavoriteHandler) Remove(c *gin.Context) {
|
||||
|
||||
// Check 批量查询给定 ids 中哪些已收藏(列表页打勾用,与收藏总量解耦)。
|
||||
//
|
||||
// POST /api/v1/me/favorites/check
|
||||
// POST /api/v1/me/favorites/checks
|
||||
// body: { ids: ["r=...","s=..."] }
|
||||
// 成功:200 { data: ["r=..."] }(仅返回已收藏的 id)
|
||||
func (h *FavoriteHandler) Check(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user