feat(marketing): add user logo management module

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
This commit is contained in:
nepiedg
2026-04-04 03:46:57 +08:00
parent 1eab1b99c1
commit b4170b4863
7 changed files with 223 additions and 1 deletions
@@ -0,0 +1,55 @@
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)
}