CS2-58: Added files filtering by requested companies ids

This commit is contained in:
KharchenkoVV 2021-08-20 11:20:24 +05:00
parent d0deefe74f
commit b39f07821d
4 changed files with 16 additions and 5 deletions

View File

@ -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; }
}
}

View File

@ -17,7 +17,7 @@ namespace AsbCloudApp.Services
string fileExtension, Stream fileStream);
Task<PaginationContainer<FileInfoDto>> GetFilesInfoAsync(int idWell,
int idCategory, DateTime begin, DateTime end,
int idCategory, IEnumerable<int> companies, DateTime begin, DateTime end,
int skip, int take, CancellationToken token = default);
Task<FileInfoDto> GetFileInfoAsync(int fileId,

View File

@ -62,8 +62,8 @@ namespace AsbCloudInfrastructure.Services
}
public async Task<PaginationContainer<FileInfoDto>> GetFilesInfoAsync(int idWell,
int idCategory, DateTime begin = default, DateTime end = default,
int skip = 0, int take = 32, CancellationToken token = default)
int idCategory, IEnumerable<int> 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<FileInfoDto>();
filePropertiesDto.AuthorName = item.Author.Name;
filePropertiesDto.CompanyId = item.Author.IdCompany != null
? item.Author.Company.Id
: 0;
result.Items.Add(filePropertiesDto);
}

View File

@ -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
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="idCategory">id категории файла</param>
/// <param name="companies">id компаний для фильтрации возвращаемых файлов</param>
/// <param name="begin">дата начала</param>
/// <param name="end">дата окончания</param>
/// <param name="skip">для пагинации кол-во записей пропустить</param>
@ -89,7 +91,8 @@ namespace AsbCloudWebApi.Controllers
[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)
IEnumerable<int> 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();