diff --git a/AsbCloudApp/Data/FileInfoDto.cs b/AsbCloudApp/Data/FileInfoDto.cs index e42bd8a5..2feda444 100644 --- a/AsbCloudApp/Data/FileInfoDto.cs +++ b/AsbCloudApp/Data/FileInfoDto.cs @@ -9,5 +9,6 @@ namespace AsbCloudApp.Data public int IdCategory { get; set; } public DateTime UploadDate { get; set; } public string AuthorName { get; set; } + public int CompanyId { get; set; } } } diff --git a/AsbCloudApp/Services/IFileService.cs b/AsbCloudApp/Services/IFileService.cs index 7bf5f884..915868e0 100644 --- a/AsbCloudApp/Services/IFileService.cs +++ b/AsbCloudApp/Services/IFileService.cs @@ -17,7 +17,7 @@ namespace AsbCloudApp.Services string fileExtension, Stream fileStream); Task> GetFilesInfoAsync(int idWell, - int idCategory, DateTime begin, DateTime end, + int idCategory, IEnumerable companies, DateTime begin, DateTime end, int skip, int take, CancellationToken token = default); Task GetFileInfoAsync(int fileId, diff --git a/AsbCloudInfrastructure/Services/FileService.cs b/AsbCloudInfrastructure/Services/FileService.cs index ea34ea5e..a036908b 100644 --- a/AsbCloudInfrastructure/Services/FileService.cs +++ b/AsbCloudInfrastructure/Services/FileService.cs @@ -62,8 +62,8 @@ namespace AsbCloudInfrastructure.Services } public async Task> GetFilesInfoAsync(int idWell, - int idCategory, DateTime begin = default, DateTime end = default, - int skip = 0, int take = 32, CancellationToken token = default) + int idCategory, IEnumerable companies = default, DateTime begin = default, + DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default) { var query = db.Files .Include(f => f.Author) @@ -72,6 +72,10 @@ namespace AsbCloudInfrastructure.Services query = query.Where(e => !e.IsDeleted); + if (companies.Any()) + query.Include(file => file.Author).ThenInclude(a => a.Company) + .Where(e => companies.Contains(e.Author.Company.Id)); + if (begin != default) query = query.Where(e => e.UploadDate >= begin); @@ -103,6 +107,9 @@ namespace AsbCloudInfrastructure.Services { var filePropertiesDto = item.Adapt(); filePropertiesDto.AuthorName = item.Author.Name; + filePropertiesDto.CompanyId = item.Author.IdCompany != null + ? item.Author.Company.Id + : 0; result.Items.Add(filePropertiesDto); } diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index 1acb26ce..68426b0a 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.IO; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -79,6 +80,7 @@ namespace AsbCloudWebApi.Controllers /// /// id скважины /// id категории файла + /// id компаний для фильтрации возвращаемых файлов /// дата начала /// дата окончания /// для пагинации кол-во записей пропустить @@ -89,7 +91,8 @@ namespace AsbCloudWebApi.Controllers [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) + IEnumerable companies = default, DateTime begin = default, + DateTime end = default, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); @@ -98,7 +101,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); var filesInfo = await fileService.GetFilesInfoAsync(idWell, idCategory, - begin, end, skip, take, token).ConfigureAwait(false); + companies, begin, end, skip, take, token).ConfigureAwait(false); if (filesInfo is null || !filesInfo.Items.Any()) return NoContent();