提交
This commit is contained in:
@@ -240,11 +240,14 @@ func joinStrings(strs []string, sep string) string {
|
||||
return result
|
||||
}
|
||||
|
||||
// ListTrashed 查询回收站文件
|
||||
func (r *FileRepository) ListTrashed(ownerID uint64) ([]model.File, error) {
|
||||
// ListTrashed 查询回收站文件(管理员看全部, 普通用户看自己的)
|
||||
func (r *FileRepository) ListTrashed(ownerID uint64, isAdmin bool) ([]model.File, error) {
|
||||
var files []model.File
|
||||
err := config.DB.Where("owner_id = ? AND status = 0", ownerID).
|
||||
Order("updated_at DESC").Find(&files).Error
|
||||
query := config.DB.Where("status = 0")
|
||||
if !isAdmin {
|
||||
query = query.Where("owner_id = ?", ownerID)
|
||||
}
|
||||
err := query.Order("updated_at DESC").Find(&files).Error
|
||||
return files, err
|
||||
}
|
||||
|
||||
@@ -253,6 +256,11 @@ func (r *FileRepository) Update(file *model.File) error {
|
||||
return config.DB.Save(file).Error
|
||||
}
|
||||
|
||||
// UpdateSize 更新文件大小
|
||||
func (r *FileRepository) UpdateSize(id uint64, size int64) error {
|
||||
return config.DB.Model(&model.File{}).Where("id = ?", id).Update("size", size).Error
|
||||
}
|
||||
|
||||
// SoftDelete 软删除(移入回收站)
|
||||
func (r *FileRepository) SoftDelete(id uint64) error {
|
||||
return config.DB.Model(&model.File{}).Where("id = ?", id).Update("status", 0).Error
|
||||
|
||||
Reference in New Issue
Block a user