update
This commit is contained in:
@ -45,7 +45,7 @@ func (s *streetSnapService) List(ctx context.Context, q dto.StreetSnapQuery) ([]
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.ID)
|
||||
list = append(list, dto.PublicStreetSnap{
|
||||
UID: hashid.Encode(r.ID),
|
||||
UID: hashid.EncodeTyped(hashid.TypeSnap, r.ID),
|
||||
Title: r.Title,
|
||||
Cover: r.Cover,
|
||||
ImageCount: r.ImageCount,
|
||||
@ -71,6 +71,8 @@ func (s *streetSnapService) attachImages(ctx context.Context, list []dto.PublicS
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// 缩略图条带剔除主图(cover),避免与卡片主图重复。cover 恒等于图片列表首张。
|
||||
imgs = excludeCoverSnap(imgs, list[i].Cover)
|
||||
if len(imgs) > limit {
|
||||
imgs = imgs[:limit]
|
||||
}
|
||||
@ -79,6 +81,20 @@ func (s *streetSnapService) attachImages(ctx context.Context, list []dto.PublicS
|
||||
return nil
|
||||
}
|
||||
|
||||
// excludeCoverSnap 同 excludeCover,作用于街拍图片列表。
|
||||
func excludeCoverSnap(imgs []model.StreetSnapImage, cover string) []model.StreetSnapImage {
|
||||
if cover == "" {
|
||||
return imgs
|
||||
}
|
||||
kept := imgs[:0]
|
||||
for _, im := range imgs {
|
||||
if im.Image != cover {
|
||||
kept = append(kept, im)
|
||||
}
|
||||
}
|
||||
return kept
|
||||
}
|
||||
|
||||
// Detail 查询街拍详情,含完整图片集。
|
||||
func (s *streetSnapService) Detail(ctx context.Context, id string) (*dto.PublicStreetSnapDetail, error) {
|
||||
snap, err := s.repo.FindByID(ctx, id)
|
||||
@ -95,7 +111,7 @@ func (s *streetSnapService) Detail(ctx context.Context, id string) (*dto.PublicS
|
||||
}
|
||||
|
||||
return &dto.PublicStreetSnapDetail{
|
||||
UID: hashid.Encode(snap.ID),
|
||||
UID: hashid.EncodeTyped(hashid.TypeSnap, snap.ID),
|
||||
Title: snap.Title,
|
||||
Cover: snap.Cover,
|
||||
Images: toPublicSnapImages(imgs),
|
||||
@ -112,7 +128,7 @@ func (s *streetSnapService) Popular(ctx context.Context, limit int) ([]dto.Publi
|
||||
list := make([]dto.PublicStreetSnap, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
list = append(list, dto.PublicStreetSnap{
|
||||
UID: hashid.Encode(r.ID),
|
||||
UID: hashid.EncodeTyped(hashid.TypeSnap, r.ID),
|
||||
Title: r.Title,
|
||||
Cover: r.Cover,
|
||||
ImageCount: r.ImageCount,
|
||||
|
||||
Reference in New Issue
Block a user