fix:分享

This commit is contained in:
2026-09-13 23:32:22 +08:00
parent 646fd99887
commit 77eec37af1
17 changed files with 903 additions and 28 deletions
+17 -8
View File
@@ -325,7 +325,12 @@ func (s *OutfitService) createItems(ctx context.Context, outfitID int64, clothes
// itemResponses 获取某穿搭的衣物明细(含图片 URL)。
func (s *OutfitService) itemResponses(ctx context.Context, outfitID int64) ([]dto.OutfitItemResponse, error) {
items, err := s.outfitItemDao.OutfitItemListByOutfitID(ctx, outfitID)
return loadOutfitItemResponses(ctx, s.outfitItemDao, s.clothesDao, outfitID)
}
// loadOutfitItemResponses 获取某穿搭的衣物明细(含图片 URL),供穿搭详情与穿搭分享复用。
func loadOutfitItemResponses(ctx context.Context, outfitItemDao *mysqldao.OutfitItemDao, clothesDao *mysqldao.ClothesDao, outfitID int64) ([]dto.OutfitItemResponse, error) {
items, err := outfitItemDao.OutfitItemListByOutfitID(ctx, outfitID)
if err != nil {
return nil, err
}
@@ -333,13 +338,13 @@ func (s *OutfitService) itemResponses(ctx context.Context, outfitID int64) ([]dt
for _, it := range items {
ids = append(ids, it.ClothesID)
}
clothesList, err := s.clothesDao.ClothesGetByIDs(ctx, ids)
clothesList, err := clothesDao.ClothesGetByIDs(ctx, ids)
if err != nil {
return nil, err
}
clothesByID := make(map[int64]mysqlmodel.Clothes, len(clothesList))
for _, c := range clothesList {
clothesByID[c.ID] = c
for i := range clothesList {
clothesByID[clothesList[i].ID] = clothesList[i]
}
resps := make([]dto.OutfitItemResponse, 0, len(items))
for _, it := range items {
@@ -402,11 +407,15 @@ func (s *OutfitService) buildOutfitListResponses(ctx context.Context, list []mys
// buildOutfitItemResponse 组装穿搭明细(processed_image 转为可访问 URL)。
func buildOutfitItemResponse(c *mysqlmodel.Clothes) dto.OutfitItemResponse {
img := c.ProcessedImage
if img != "" {
img = upload.GetCosUrl(img)
return dto.OutfitItemResponse{ClothesUUID: c.ClothesUUID, ProcessedImage: clothesImageURL(c.ProcessedImage)}
}
// clothesImageURL 将衣物抠图相对路径转为可访问 URL(空则返回空)。
func clothesImageURL(processed string) string {
if processed == "" {
return ""
}
return dto.OutfitItemResponse{ClothesUUID: c.ClothesUUID, ProcessedImage: img}
return upload.GetCosUrl(processed)
}
// buildOutfitCreateResponse 组装穿搭响应。