b4170b4863
Users can now save uploaded logos to the backend (marketing_user_logos table), avoiding repeated uploads. Includes CRUD endpoints: list, save, delete with a per-user limit of 10 logos. Made-with: Cursor
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"wx_service/internal/marketing/model"
|
|
"wx_service/internal/marketing/repository"
|
|
)
|
|
|
|
const MaxLogosPerUser = 10
|
|
|
|
var ErrLogoLimitReached = errors.New("Logo 数量已达上限")
|
|
|
|
type UserLogoService struct {
|
|
repo *repository.UserLogoRepository
|
|
}
|
|
|
|
func NewUserLogoService(repo *repository.UserLogoRepository) *UserLogoService {
|
|
return &UserLogoService{repo: repo}
|
|
}
|
|
|
|
type SaveLogoRequest struct {
|
|
URL string `json:"url" binding:"required"`
|
|
Filename string `json:"filename"`
|
|
FileSize int64 `json:"file_size"`
|
|
}
|
|
|
|
func (s *UserLogoService) Save(userID uint, req SaveLogoRequest) (*model.UserLogo, error) {
|
|
count, err := s.repo.CountByUser(userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if count >= MaxLogosPerUser {
|
|
return nil, ErrLogoLimitReached
|
|
}
|
|
|
|
logo := &model.UserLogo{
|
|
UserID: userID,
|
|
URL: req.URL,
|
|
Filename: req.Filename,
|
|
FileSize: req.FileSize,
|
|
}
|
|
if err := s.repo.Create(logo); err != nil {
|
|
return nil, err
|
|
}
|
|
return logo, nil
|
|
}
|
|
|
|
func (s *UserLogoService) List(userID uint) ([]model.UserLogo, error) {
|
|
return s.repo.FindByUser(userID)
|
|
}
|
|
|
|
func (s *UserLogoService) Delete(id, userID uint) error {
|
|
return s.repo.Delete(id, userID)
|
|
}
|