feat: 完成 #38 营销图CRUD接口下载校验与测试
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
var (
|
||||
ErrDownloadTemplateRequired = errors.New("请选择模板")
|
||||
ErrDownloadTemplateDisabled = errors.New("模板已禁用")
|
||||
)
|
||||
|
||||
type DownloadService struct {
|
||||
@@ -44,6 +45,14 @@ func (s *DownloadService) Create(userID uint, req CreateDownloadRequest) (*model
|
||||
return nil, ErrDownloadTemplateRequired
|
||||
}
|
||||
|
||||
tpl, err := s.templateRepo.FindByID(req.TemplateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tpl.Status != 1 {
|
||||
return nil, ErrDownloadTemplateDisabled
|
||||
}
|
||||
|
||||
dl := &model.MarketingDownload{
|
||||
UserID: userID,
|
||||
TemplateID: req.TemplateID,
|
||||
@@ -58,7 +67,9 @@ func (s *DownloadService) Create(userID uint, req CreateDownloadRequest) (*model
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = s.templateRepo.IncrementDownloadCount(req.TemplateID)
|
||||
if err := s.templateRepo.IncrementDownloadCount(req.TemplateID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dl, nil
|
||||
}
|
||||
|
||||
@@ -86,6 +97,7 @@ func (s *DownloadService) GetStats() (*repository.DownloadStats, error) {
|
||||
// IsBadRequestError checks if the error is a client-side validation error.
|
||||
func IsBadRequestError(err error) bool {
|
||||
return errors.Is(err, ErrDownloadTemplateRequired) ||
|
||||
errors.Is(err, ErrDownloadTemplateDisabled) ||
|
||||
errors.Is(err, ErrCategoryNameRequired) ||
|
||||
errors.Is(err, ErrCategoryNameTooLong) ||
|
||||
errors.Is(err, ErrCategoryHasTemplates) ||
|
||||
|
||||
Reference in New Issue
Block a user