Add user files.

This commit is contained in:
2025-07-13 16:41:39 +08:00
parent e9f6e1968e
commit 891b3d4a1a
8 changed files with 236 additions and 14 deletions

View File

@@ -215,3 +215,20 @@ func SetFileStorageKeyAndSize(id string, storageKey string, size int64) error {
}
return nil
}
func ListUserFiles(userID uint, page, pageSize int) ([]*model.File, int64, error) {
var files []*model.File
var count int64
if err := db.Model(&model.File{}).
Preload("Resource").
Where("user_id = ?", userID).
Count(&count).
Order("created_at DESC").
Offset((page - 1) * pageSize).
Limit(pageSize).
Find(&files).Error; err != nil {
return nil, 0, err
}
return files, count, nil
}