update
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"fashionapi/internal/dto"
|
||||
"fashionapi/internal/model"
|
||||
@ -168,8 +167,9 @@ func (s *articleService) Detail(ctx context.Context, id string, locale string) (
|
||||
return nil, internalErr(err.Error())
|
||||
}
|
||||
|
||||
// 默认仅主图(is_detail=0)进 Images;细节图按 look_index 分组进 Details,
|
||||
// 供前端「细节入口」按需展开。这样既满足「默认只展示主图」,又不丢失细节图数据。
|
||||
// 主图(is_detail=0)进 Images,默认展示;细节图(is_detail=1)按 look_index
|
||||
// 直接挂到所属主图的 Detail 子数组下 —— 「look → 细节」的层级与前端 UI 一致,
|
||||
// 前端读 img.detail 即可,无需再单独维护一份「按 look_index 分组」的映射表。
|
||||
mains := make([]model.BrandRunwayImage, 0, len(imgs))
|
||||
byLook := make(map[uint32][]model.BrandRunwayImage)
|
||||
for _, im := range imgs {
|
||||
@ -179,17 +179,14 @@ func (s *articleService) Detail(ctx context.Context, id string, locale string) (
|
||||
byLook[im.LookIndex] = append(byLook[im.LookIndex], im)
|
||||
}
|
||||
}
|
||||
details := make([]dto.RunwayLookDetails, 0, len(byLook))
|
||||
lookIdxs := make([]uint32, 0, len(byLook))
|
||||
for k := range byLook {
|
||||
lookIdxs = append(lookIdxs, k)
|
||||
}
|
||||
sort.Slice(lookIdxs, func(i, j int) bool { return lookIdxs[i] < lookIdxs[j] })
|
||||
for _, k := range lookIdxs {
|
||||
details = append(details, dto.RunwayLookDetails{
|
||||
LookIndex: k,
|
||||
Images: s.toPublicImages(byLook[k]),
|
||||
})
|
||||
pubMains := s.toPublicImages(mains)
|
||||
for i := range pubMains {
|
||||
// 挂载后即从 byLook 摘除:主图 look_index 若有重复,只归属第一张,避免同一批
|
||||
// 细节图被复制进多个主图(正常数据不会重复,此处仅作防御)。
|
||||
if kids, ok := byLook[pubMains[i].LookIndex]; ok && len(kids) > 0 {
|
||||
pubMains[i].Detail = s.toPublicImages(kids)
|
||||
delete(byLook, pubMains[i].LookIndex)
|
||||
}
|
||||
}
|
||||
|
||||
return &dto.PublicArticleDetail{
|
||||
@ -200,8 +197,7 @@ func (s *articleService) Detail(ctx context.Context, id string, locale string) (
|
||||
Cover: s.img.Compose(row.Cover),
|
||||
// 品牌名强制优先英文("en"),不随 locale 切换,保持英文观感。
|
||||
BrandName: pickLocale(row.BrandNameEn, row.BrandNameCn, "en"),
|
||||
Images: s.toPublicImages(mains),
|
||||
Details: details,
|
||||
Images: pubMains,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user