update
This commit is contained in:
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
@ -29,6 +30,9 @@ type BrandService interface {
|
||||
Create(ctx context.Context, nameEn, nameCn string) (string, error)
|
||||
// Update 按编码 id 更新品牌名称。
|
||||
Update(ctx context.Context, uid, nameEn, nameCn string) error
|
||||
// Delete 软删品牌(is_deleted=1)。品牌下仍有未删除的走秀档案时拒绝删除,
|
||||
// 避免留下 brand_id 指不到品牌的图集(无外键级联)。
|
||||
Delete(ctx context.Context, uid string) error
|
||||
// CrawlTasks 返回爬虫抓取所需的品牌列表(编码 brand_uid + 英文品牌名)。
|
||||
// brandID>0 时仅返回该品牌(对应 --brand 单品牌调试)。
|
||||
CrawlTasks(ctx context.Context, brandID uint32) ([]dto.CrawlBrand, error)
|
||||
@ -170,6 +174,31 @@ func (s *brandService) Update(ctx context.Context, uid, nameEn, nameCn string) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete 软删品牌:先确认该品牌下没有未删除的走秀档案,再置 is_deleted=1。
|
||||
//
|
||||
// 护栏的理由:brand_runways.brand_id 没有外键级联,直接删品牌会留下一批指不到品牌的图集,
|
||||
// 前台品牌页、热门榜、图集列表都会出现异常数据。宁可让运营先处理档案,也不引入隐式级联删除。
|
||||
func (s *brandService) Delete(ctx context.Context, uid string) error {
|
||||
id, err := hashid.Decode(uid)
|
||||
if err != nil {
|
||||
return ErrBrandNotFound
|
||||
}
|
||||
n, err := s.brands.CountRunwaysByBrand(ctx, id)
|
||||
if err != nil {
|
||||
return internalErr(err.Error())
|
||||
}
|
||||
if n > 0 {
|
||||
return NewError(http.StatusConflict, fmt.Sprintf("该品牌下还有 %d 个图集,请先删除或下架后再删品牌", n))
|
||||
}
|
||||
if err := s.brands.SetDeleted(ctx, id, 1); err != nil {
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
return ErrBrandNotFound
|
||||
}
|
||||
return internalErr(err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CrawlTasks 返回爬虫取任务所需的品牌列表:编码 brand_uid + 英文品牌名。
|
||||
// 爬虫直接拿 brand_uid 上送 ingest,无需自己编码;name 用于拼 vogue 抓取 URL。
|
||||
func (s *brandService) CrawlTasks(ctx context.Context, brandID uint32) ([]dto.CrawlBrand, error) {
|
||||
|
||||
Reference in New Issue
Block a user