// Package wallpaper 壁纸模块控制器。 // // 分两个控制器: // - Controller(admin):后台图库管理与平台配置,走 RBAC 权限; // - OpenController(open):前台读取,免鉴权。 // // 控制器只做「参数搬运 + 结构转换」,业务逻辑一律在 internal/service/wallpaper。 package wallpaper import ( wallpaperv1 "service.xpcool.com/api/wallpaper" "service.xpcool.com/internal/model/dto" ) // toAPIItem 把领域 DTO 转成接口输出结构。 // 两者字段一一对应,单独转换是为了让 API 契约与内部结构可以各自演进。 func toAPIItem(v *dto.WallpaperItem) *wallpaperv1.Item { if v == nil { return nil } return &wallpaperv1.Item{ Id: v.Id, Title: v.Title, Width: v.Width, Height: v.Height, Orientation: v.Orientation, ThumbUrl: v.ThumbUrl, PreviewUrl: v.PreviewUrl, FullUrl: v.FullUrl, Source: v.Source, SourceName: v.SourceName, FromOpen: v.FromOpen, Author: v.Author, AuthorUrl: v.AuthorUrl, PageUrl: v.PageUrl, License: v.License, Tags: v.Tags, Category: v.Category, Filesize: v.Filesize, CreatedAt: v.CreatedAt, } } // toAPIItems 批量转换。 func toAPIItems(list []dto.WallpaperItem) []*wallpaperv1.Item { out := make([]*wallpaperv1.Item, 0, len(list)) for i := range list { out = append(out, toAPIItem(&list[i])) } return out } // toAPISource 把平台信息转成接口输出结构。 func toAPISource(v *dto.WallpaperSourceInfo) *wallpaperv1.SourceInfo { return &wallpaperv1.SourceInfo{ Code: v.Code, Name: v.Name, Enabled: v.Enabled, Sort: v.Sort, Configured: v.Configured, Available: v.Available, Hint: v.Hint, Remark: v.Remark, HasApiKey: v.HasApiKey, } }