update
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"fashionapi/internal/dto"
|
||||
"fashionapi/internal/middleware"
|
||||
"fashionapi/internal/pkg/hashid"
|
||||
"fashionapi/internal/pkg/response"
|
||||
"fashionapi/internal/service"
|
||||
@ -15,12 +16,13 @@ import (
|
||||
|
||||
// StreetSnapHandler 对外公开的街拍接口。
|
||||
type StreetSnapHandler struct {
|
||||
svc service.StreetSnapService
|
||||
svc service.StreetSnapService
|
||||
favs service.FavoriteService
|
||||
}
|
||||
|
||||
// NewStreetSnapHandler 创建街拍 handler。
|
||||
func NewStreetSnapHandler(svc service.StreetSnapService) *StreetSnapHandler {
|
||||
return &StreetSnapHandler{svc: svc}
|
||||
func NewStreetSnapHandler(svc service.StreetSnapService, favs service.FavoriteService) *StreetSnapHandler {
|
||||
return &StreetSnapHandler{svc: svc, favs: favs}
|
||||
}
|
||||
|
||||
// List 街拍列表(分页 + 排序 + 年份过滤)。
|
||||
@ -93,5 +95,28 @@ func (h *StreetSnapHandler) Detail(c *gin.Context) {
|
||||
detail.Images = detail.Images[:dto.PreviewLimit]
|
||||
preview = true
|
||||
}
|
||||
|
||||
// 已登录:图集(gallery 级 s=)与每张图片(image 级 j=)收藏态随详情返回,
|
||||
// 前端无需再单独调 /me/favorites/checks。
|
||||
if uid, ok := middleware.UserIDFrom(c); ok {
|
||||
ids := make([]string, 0, len(detail.Images)+1)
|
||||
ids = append(ids, detail.UID)
|
||||
for _, im := range detail.Images {
|
||||
if im.ID != "" {
|
||||
ids = append(ids, im.ID)
|
||||
}
|
||||
}
|
||||
if hit, err := h.favs.Check(c.Request.Context(), uid, ids); err == nil {
|
||||
set := make(map[string]bool, len(hit))
|
||||
for _, id := range hit {
|
||||
set[id] = true
|
||||
}
|
||||
detail.Favorited = set[detail.UID]
|
||||
for i := range detail.Images {
|
||||
detail.Images[i].Favorited = set[detail.Images[i].ID]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.DataPreview(c, http.StatusOK, detail, preview, imageTotal)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user