fix(publish): 后台详情与品牌列表改读基表,修复未发布内容在后台不可达
This commit is contained in:
@ -18,10 +18,15 @@ type ArticleRepository interface {
|
||||
List(ctx context.Context, q dto.ArticleQuery) ([]model.RunwayRow, int64, error)
|
||||
// ListAdmin 后台管理列表:投影列含 season/year/collection_type/season_code 等管理字段。
|
||||
ListAdmin(ctx context.Context, q dto.ArticleQuery) ([]model.RunwayRow, int64, error)
|
||||
// FindByID 查询单篇文章(含 JOIN 出的品牌名)。不存在时返回 ErrNotFound。
|
||||
// FindByID 公开读:查询单篇文章(含 JOIN 出的品牌名)。不存在时返回 ErrNotFound。
|
||||
FindByID(ctx context.Context, id string) (*model.RunwayRow, error)
|
||||
// ListImages 查询某篇文章的全部图片,按排序值升序。
|
||||
// FindByIDBase 后台读基表:与 FindByID 同投影/同 JOIN,但能看到 pending / rejected。
|
||||
// 后台列表故意展示待审行并链到详情页,详情必须走基表,否则待审项点进去 404。
|
||||
FindByIDBase(ctx context.Context, id string) (*model.RunwayRow, error)
|
||||
// ListImages 公开读:查询某篇文章的全部图片,按排序值升序(未发布图片不可见)。
|
||||
ListImages(ctx context.Context, runwayID string) ([]model.BrandRunwayImage, error)
|
||||
// ListImagesBase 后台读基表:与 ListImages 同形,但含未发布图片(后台详情/编辑需要)。
|
||||
ListImagesBase(ctx context.Context, runwayID string) ([]model.BrandRunwayImage, error)
|
||||
// ImagesByRunwayIDs 批量查询多篇文章的图片,单次 IN 查询避免 N+1。
|
||||
ImagesByRunwayIDs(ctx context.Context, ids []uint32) (map[uint32][]model.BrandRunwayImage, error)
|
||||
// GetForEdit 取原始走秀记录(含全部 en/cn 字段)与图片,供后台编辑表单预填。
|
||||
@ -196,11 +201,20 @@ func (r *articleRepository) ListAdmin(ctx context.Context, q dto.ArticleQuery) (
|
||||
return rows, total, nil
|
||||
}
|
||||
|
||||
// FindByID 公开读:读公开视图,pending / rejected 视同不存在(返回 ErrNotFound)。
|
||||
func (r *articleRepository) FindByID(ctx context.Context, id string) (*model.RunwayRow, error) {
|
||||
return r.findByID(r.db.WithContext(ctx).Table(publicRunways), id)
|
||||
}
|
||||
|
||||
// FindByIDBase 后台读基表:同投影同 JOIN,但不过滤 status(后台详情需渲染待审内容)。
|
||||
func (r *articleRepository) FindByIDBase(ctx context.Context, id string) (*model.RunwayRow, error) {
|
||||
return r.findByID(r.db.WithContext(ctx).Model(&model.BrandRunway{}), id)
|
||||
}
|
||||
|
||||
// findByID 用给定查询(视图或基表)取单行;投影与 JOIN 两处保持一致,避免公开/后台口径漂移。
|
||||
func (r *articleRepository) findByID(q *gorm.DB, id string) (*model.RunwayRow, error) {
|
||||
var row model.RunwayRow
|
||||
err := r.db.WithContext(ctx).
|
||||
Table(publicRunways).
|
||||
Select(articleDetailColumns).
|
||||
err := q.Select(articleDetailColumns).
|
||||
Joins(brandJoin).
|
||||
Where("brand_runways.id = ? AND brand_runways.is_deleted = 0", id).
|
||||
First(&row).Error
|
||||
@ -224,8 +238,8 @@ func (r *articleRepository) ListImages(ctx context.Context, runwayID string) ([]
|
||||
return imgs, err
|
||||
}
|
||||
|
||||
// listImagesBase 读基表(含未发布),仅供后台 GetForEdit 使用 —— 否则编辑待审内容时看不到图。
|
||||
func (r *articleRepository) listImagesBase(ctx context.Context, runwayID string) ([]model.BrandRunwayImage, error) {
|
||||
// ListImagesBase 读基表(含未发布),供后台 GetForEdit / 后台详情使用 —— 否则待审内容看不到图。
|
||||
func (r *articleRepository) ListImagesBase(ctx context.Context, runwayID string) ([]model.BrandRunwayImage, error) {
|
||||
var imgs []model.BrandRunwayImage
|
||||
err := r.db.WithContext(ctx).
|
||||
Where("runway_id = ? AND is_deleted = 0", runwayID).
|
||||
@ -278,7 +292,7 @@ func (r *articleRepository) GetForEdit(ctx context.Context, id uint32) (*model.B
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
imgs, err := r.listImagesBase(ctx, strconv.FormatUint(uint64(id), 10))
|
||||
imgs, err := r.ListImagesBase(ctx, strconv.FormatUint(uint64(id), 10))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user