CS2-58 FileController Add filter by filename

This commit is contained in:
Фролов 2021-08-31 09:59:23 +05:00
parent e8bfe3b443
commit b3b1230c0a
3 changed files with 16 additions and 7 deletions

View File

@ -14,7 +14,7 @@ namespace AsbCloudApp.Services
Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default);
Task<PaginationContainer<FileInfoDto>> GetInfosAsync(int idWell,
int idCategory, IEnumerable<int> companies, DateTime begin, DateTime end,
int idCategory, IEnumerable<int> companies, string fileName, DateTime begin, DateTime end,
int skip, int take, CancellationToken token = default);
Task<FileInfoDto> GetInfoAsync(int fileId,

View File

@ -73,7 +73,7 @@ namespace AsbCloudInfrastructure.Services
}
public async Task<PaginationContainer<FileInfoDto>> GetInfosAsync(int idWell,
int idCategory, IEnumerable<int> companies = default, DateTime begin = default,
int idCategory, IEnumerable<int> companies = default, string fileName = default, DateTime begin = default,
DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default)
{
var query = db.Files
@ -87,6 +87,9 @@ namespace AsbCloudInfrastructure.Services
query.Include(file => file.Author).ThenInclude(a => a.Company)
.Where(e => companies.Contains(e.Author.Company.Id));
if (!string.IsNullOrEmpty(fileName))
query = query.Where(e => e.Name.Contains(fileName, StringComparison.OrdinalIgnoreCase));
if (begin != default)
query = query.Where(e => e.UploadDate >= begin);

View File

@ -104,10 +104,16 @@ namespace AsbCloudWebApi.Controllers
/// <returns>Список информации о файлах в этой категории</returns>
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetFilesInfoAsync([FromRoute] int idWell,
int skip = 0, int take = 32, int idCategory = default,
DateTime begin = default, DateTime end = default,
CancellationToken token = default, [FromQuery] IEnumerable<int> companies = default)
public async Task<IActionResult> GetFilesInfoAsync(
[FromRoute] int idWell,
int idCategory = default,
[FromQuery] IEnumerable<int> companies = default,
string fileName = default,
DateTime begin = default,
DateTime end = default,
int skip = 0,
int take = 32,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
@ -116,7 +122,7 @@ namespace AsbCloudWebApi.Controllers
return Forbid();
var filesInfo = await fileService.GetInfosAsync(idWell, idCategory,
companies, begin, end, skip, take, token).ConfigureAwait(false);
companies, fileName, begin, end, skip, take, token).ConfigureAwait(false);
if (filesInfo is null || !filesInfo.Items.Any())
return NoContent();