From b3b1230c0a371d1e19edc6924d2de74829e1be46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Tue, 31 Aug 2021 09:59:23 +0500 Subject: [PATCH] CS2-58 FileController Add filter by filename --- AsbCloudApp/Services/IFileService.cs | 2 +- AsbCloudInfrastructure/Services/FileService.cs | 5 ++++- AsbCloudWebApi/Controllers/FileController.cs | 16 +++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/AsbCloudApp/Services/IFileService.cs b/AsbCloudApp/Services/IFileService.cs index c0b3e489..4b0ac894 100644 --- a/AsbCloudApp/Services/IFileService.cs +++ b/AsbCloudApp/Services/IFileService.cs @@ -14,7 +14,7 @@ namespace AsbCloudApp.Services Task SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default); Task> GetInfosAsync(int idWell, - int idCategory, IEnumerable companies, DateTime begin, DateTime end, + int idCategory, IEnumerable companies, string fileName, DateTime begin, DateTime end, int skip, int take, CancellationToken token = default); Task GetInfoAsync(int fileId, diff --git a/AsbCloudInfrastructure/Services/FileService.cs b/AsbCloudInfrastructure/Services/FileService.cs index c020493c..7a14d231 100644 --- a/AsbCloudInfrastructure/Services/FileService.cs +++ b/AsbCloudInfrastructure/Services/FileService.cs @@ -73,7 +73,7 @@ namespace AsbCloudInfrastructure.Services } public async Task> GetInfosAsync(int idWell, - int idCategory, IEnumerable companies = default, DateTime begin = default, + int idCategory, IEnumerable 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); diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index aa68544b..ed95da6b 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -104,10 +104,16 @@ namespace AsbCloudWebApi.Controllers /// Список информации о файлах в этой категории [HttpGet] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] - public async Task GetFilesInfoAsync([FromRoute] int idWell, - int skip = 0, int take = 32, int idCategory = default, - DateTime begin = default, DateTime end = default, - CancellationToken token = default, [FromQuery] IEnumerable companies = default) + public async Task GetFilesInfoAsync( + [FromRoute] int idWell, + int idCategory = default, + [FromQuery] IEnumerable 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();