refactor: 移除全局单例、修复分层违规、统一错误与响应
Some checks failed
Build / build (push) Successful in 7m52s
Build / build-docker (push) Has been cancelled

This commit is contained in:
lafay
2026-06-15 16:40:36 +08:00
parent d9de39a0a3
commit 7d1c78f965
55 changed files with 593 additions and 1744 deletions

View File

@@ -210,3 +210,27 @@ func (r *textureRepository) CountByUploaderID(ctx context.Context, uploaderID in
Count(&count).Error
return count, err
}
// ListForAdmin 管理员分页查询材质列表(含 Uploader 预加载,无权限过滤)
func (r *textureRepository) ListForAdmin(ctx context.Context, page, pageSize int) ([]*model.Texture, int64, error) {
var textures []*model.Texture
var total int64
db := r.db.WithContext(ctx).Model(&model.Texture{})
if err := db.Count(&total).Error; err != nil {
return nil, 0, err
}
offset := (page - 1) * pageSize
if err := db.Preload("Uploader").Order("id DESC").Offset(offset).Limit(pageSize).Find(&textures).Error; err != nil {
return nil, 0, err
}
return textures, total, nil
}
// FindByIDForAdmin 管理员查询材质(无权限过滤,用于管理员删除前检查存在性)
func (r *textureRepository) FindByIDForAdmin(ctx context.Context, id int64) (*model.Texture, error) {
var texture model.Texture
err := r.db.WithContext(ctx).Where("id = ?", id).First(&texture).Error
return handleNotFoundResult(&texture, err)
}