package service import ( "context" "time" "github.com/topfans/backend/gateway/repository" "github.com/topfans/backend/pkg/models" ) // SyncVersionRequest uniCloud 同步请求体 // 注:定义在 service 包(而非 controller 包),避免 controller ↔ service 循环依赖 type SyncVersionRequest struct { Android *PlatformVersionInfo `json:"android"` IOS *PlatformVersionInfo `json:"ios"` } // PlatformVersionInfo 单个平台的版本信息 type PlatformVersionInfo struct { URL string `json:"url" binding:"required"` Version string `json:"version"` Type string `json:"type" binding:"required,oneof=native_app wgt"` } // appDownloadRepo 下载配置仓库接口(仅暴露 service 层需要的两个方法) type appDownloadRepo interface { FindByType(ctx context.Context, pkgType string) ([]models.AppDownloadConfig, error) UpsertAll(ctx context.Context, configs []models.AppDownloadConfig) error } // AppDownloadService App下载页业务逻辑 type AppDownloadService struct { repo appDownloadRepo } // NewAppDownloadService 构造函数 func NewAppDownloadService(repo *repository.AppDownloadRepository) *AppDownloadService { return &AppDownloadService{repo: repo} } // GetAllNativeApp 获取所有 native_app 类型的下载配置 func (s *AppDownloadService) GetAllNativeApp(ctx context.Context) ([]models.AppDownloadConfig, error) { return s.repo.FindByType(ctx, models.AppPackageTypeNativeApp) } // SyncVersion 同步版本信息(upsert) func (s *AppDownloadService) SyncVersion(ctx context.Context, req *SyncVersionRequest) error { now := time.Now().UnixMilli() var configs []models.AppDownloadConfig if req.Android != nil { configs = append(configs, models.AppDownloadConfig{ Platform: "android", Type: req.Android.Type, DownloadURL: req.Android.URL, Version: req.Android.Version, UpdatedAt: now, }) } if req.IOS != nil { configs = append(configs, models.AppDownloadConfig{ Platform: "ios", Type: req.IOS.Type, DownloadURL: req.IOS.URL, Version: req.IOS.Version, UpdatedAt: now, }) } return s.repo.UpsertAll(ctx, configs) }