refactor(publish): 公开读改走只读视图,后台仍读基表
This commit is contained in:
@ -17,6 +17,8 @@ import (
|
||||
// StreetSnapService 街拍业务接口。
|
||||
type StreetSnapService interface {
|
||||
List(ctx context.Context, q dto.StreetSnapQuery) ([]dto.PublicStreetSnap, int64, error)
|
||||
// AdminList 后台街拍列表:读基表,包含 pending / rejected(否则审核员看不到待审内容)。
|
||||
AdminList(ctx context.Context, q dto.StreetSnapQuery) ([]dto.PublicStreetSnap, int64, error)
|
||||
Detail(ctx context.Context, id string) (*dto.PublicStreetSnapDetail, error)
|
||||
// Popular 返回热度前 N 个街拍(按图片数降序),供 SSG 首页热门街拍展示。
|
||||
Popular(ctx context.Context, limit int) ([]dto.PublicStreetSnap, error)
|
||||
@ -62,17 +64,11 @@ func (s *streetSnapService) List(ctx context.Context, q dto.StreetSnapQuery) ([]
|
||||
return nil, 0, internalErr(err.Error())
|
||||
}
|
||||
|
||||
list := make([]dto.PublicStreetSnap, 0, len(rows))
|
||||
ids := make([]uint32, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.ID)
|
||||
list = append(list, dto.PublicStreetSnap{
|
||||
UID: hashid.EncodeWithType(r.ID, hashid.TypeSnap),
|
||||
Title: r.Title,
|
||||
Cover: s.img.ComposeThumb(r.Cover), // 列表封面走缩略图样式(小尺寸省流量)
|
||||
ImageCount: r.ImageCount,
|
||||
})
|
||||
}
|
||||
list := s.toPublicSnaps(rows)
|
||||
|
||||
if q.Images > 0 && len(list) > 0 {
|
||||
if err := s.attachImages(ctx, list, ids, q.Images); err != nil {
|
||||
@ -82,6 +78,35 @@ func (s *streetSnapService) List(ctx context.Context, q dto.StreetSnapQuery) ([]
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// AdminList 后台街拍列表:读基表,包含 pending / rejected。
|
||||
//
|
||||
// 与 List 用同一个映射(toPublicSnaps),但列表不附图——后台列表只展示卡片字段,
|
||||
// 与走秀后台 AdminList 的口径一致。
|
||||
func (s *streetSnapService) AdminList(ctx context.Context, q dto.StreetSnapQuery) ([]dto.PublicStreetSnap, int64, error) {
|
||||
q.Normalize()
|
||||
|
||||
rows, total, err := s.repo.ListAdmin(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, internalErr(err.Error())
|
||||
}
|
||||
return s.toPublicSnaps(rows), total, nil
|
||||
}
|
||||
|
||||
// toPublicSnaps 把街拍实体映射为对外列表结构(卡片字段:编码 id / 标题 / 缩略封面 / 图片数)。
|
||||
// 公开 List 与后台 AdminList 共用,避免两处重复维护映射(封面统一走缩略图样式,小尺寸省流量)。
|
||||
func (s *streetSnapService) toPublicSnaps(rows []model.StreetSnap) []dto.PublicStreetSnap {
|
||||
list := make([]dto.PublicStreetSnap, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
list = append(list, dto.PublicStreetSnap{
|
||||
UID: hashid.EncodeWithType(r.ID, hashid.TypeSnap),
|
||||
Title: r.Title,
|
||||
Cover: s.img.ComposeThumb(r.Cover),
|
||||
ImageCount: r.ImageCount,
|
||||
})
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// attachImages 用单次 IN 查询为列表批量补齐图片,避免前端逐条请求详情。
|
||||
func (s *streetSnapService) attachImages(ctx context.Context, list []dto.PublicStreetSnap, ids []uint32, limit int) error {
|
||||
grouped, err := s.repo.ImagesBySnapIDs(ctx, ids)
|
||||
|
||||
Reference in New Issue
Block a user