Skip to content

Commit

Permalink
Merge pull request #110 from EasyAbp/fix-sorting
Browse files Browse the repository at this point in the history
Fix the sorting of the file list API
  • Loading branch information
gdlcf88 committed Nov 27, 2023
2 parents 8787199 + c4e15ef commit 9fe2b04
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using EasyAbp.FileManagement.Containers;
using EasyAbp.FileManagement.Files.Dtos;
Expand Down Expand Up @@ -67,16 +68,21 @@ public override async Task<PagedResultDto<FileInfoDto>> GetListAsync(GetFileList
);
}

protected override IQueryable<File> ApplySorting(IQueryable<File> query, GetFileListInput input)
{
return input.Sorting.IsNullOrWhiteSpace()
? query.OrderBy(x => x.FileType).ThenBy(x => x.FileName)
: query.OrderBy(x => x.FileType).ThenBy(input.Sorting!);
}

protected override async Task<IQueryable<File>> CreateFilteredQueryAsync(GetFileListInput input)
{
await Task.CompletedTask;

return (await _repository.GetQueryableAsync())
.Where(x => x.ParentId == input.ParentId && x.OwnerUserId == input.OwnerUserId &&
x.FileContainerName == input.FileContainerName)
.WhereIf(input.DirectoryOnly, x => x.FileType == FileType.Directory)
.OrderBy(x => x.FileType)
.ThenBy(x => x.FileName);
.WhereIf(input.DirectoryOnly, x => x.FileType == FileType.Directory);
}

[Authorize]
Expand Down

0 comments on commit 9fe2b04

Please sign in to comment.