1c0aeb152a
- Add PUT /auth/profile endpoint for nickname and avatar updates - Add ad_placements table and CRUD admin API for managing ad units - Add GET /marketing/ad-config public API for mini-program to fetch ad config - Reduce logo limit from 10 to 3 per user, add 2MB file size validation Made-with: Cursor
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"wx_service/internal/marketing/model"
|
|
"wx_service/internal/marketing/repository"
|
|
)
|
|
|
|
const MaxLogosPerUser = 3
|
|
const MaxLogoFileSize = 2 * 1024 * 1024 // 2MB
|
|
|
|
var (
|
|
ErrLogoLimitReached = errors.New("Logo 数量已达上限")
|
|
ErrLogoTooLarge = errors.New("Logo 文件不能超过 2MB")
|
|
)
|
|
|
|
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) {
|
|
if req.FileSize > MaxLogoFileSize {
|
|
return nil, ErrLogoTooLarge
|
|
}
|
|
|
|
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)
|
|
}
|