refactor(publish): 公开读改走只读视图,后台仍读基表
This commit is contained in:
@ -142,7 +142,7 @@ func (r *articleRepository) List(ctx context.Context, q dto.ArticleQuery) ([]mod
|
||||
|
||||
var total int64
|
||||
if err := r.db.WithContext(ctx).
|
||||
Model(&model.BrandRunway{}).
|
||||
Table(publicRunways).
|
||||
Scopes(scope).
|
||||
Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
@ -153,7 +153,7 @@ func (r *articleRepository) List(ctx context.Context, q dto.ArticleQuery) ([]mod
|
||||
|
||||
var rows []model.RunwayRow
|
||||
if err := r.db.WithContext(ctx).
|
||||
Model(&model.BrandRunway{}).
|
||||
Table(publicRunways).
|
||||
Scopes(scope).
|
||||
Select(articleListColumns).
|
||||
Joins(brandJoin).
|
||||
@ -199,7 +199,7 @@ func (r *articleRepository) ListAdmin(ctx context.Context, q dto.ArticleQuery) (
|
||||
func (r *articleRepository) FindByID(ctx context.Context, id string) (*model.RunwayRow, error) {
|
||||
var row model.RunwayRow
|
||||
err := r.db.WithContext(ctx).
|
||||
Model(&model.BrandRunway{}).
|
||||
Table(publicRunways).
|
||||
Select(articleDetailColumns).
|
||||
Joins(brandJoin).
|
||||
Where("brand_runways.id = ? AND brand_runways.is_deleted = 0", id).
|
||||
@ -213,7 +213,19 @@ func (r *articleRepository) FindByID(ctx context.Context, id string) (*model.Run
|
||||
return &row, nil
|
||||
}
|
||||
|
||||
// ListImages 公开读:读公开视图,未发布走秀的图片不可见(视图已含 is_deleted 过滤)。
|
||||
func (r *articleRepository) ListImages(ctx context.Context, runwayID string) ([]model.BrandRunwayImage, error) {
|
||||
var imgs []model.BrandRunwayImage
|
||||
err := r.db.WithContext(ctx).
|
||||
Table(publicRunwayImages).
|
||||
Where("runway_id = ?", runwayID).
|
||||
Order("sort_order ASC, id ASC").
|
||||
Find(&imgs).Error
|
||||
return imgs, err
|
||||
}
|
||||
|
||||
// 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).
|
||||
@ -230,8 +242,9 @@ func (r *articleRepository) ImagesByRunwayIDs(ctx context.Context, ids []uint32)
|
||||
|
||||
var imgs []model.BrandRunwayImage
|
||||
err := r.db.WithContext(ctx).
|
||||
Table(publicRunwayImages).
|
||||
Select("runway_id, image, name, sort_order").
|
||||
Where("runway_id IN ? AND is_deleted = 0 AND is_detail = 0", ids).
|
||||
Where("runway_id IN ? AND is_detail = 0", ids).
|
||||
Order("sort_order ASC, id ASC").
|
||||
Find(&imgs).Error
|
||||
if err != nil {
|
||||
@ -265,7 +278,7 @@ func (r *articleRepository) GetForEdit(ctx context.Context, id uint32) (*model.B
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
imgs, err := r.ListImages(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