forked from ddrilling/AsbCloudServer
CS2-58: Added files filtering by requested companies ids
This commit is contained in:
parent
d0deefe74f
commit
b39f07821d
@ -9,5 +9,6 @@ namespace AsbCloudApp.Data
|
|||||||
public int IdCategory { get; set; }
|
public int IdCategory { get; set; }
|
||||||
public DateTime UploadDate { get; set; }
|
public DateTime UploadDate { get; set; }
|
||||||
public string AuthorName { get; set; }
|
public string AuthorName { get; set; }
|
||||||
|
public int CompanyId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace AsbCloudApp.Services
|
|||||||
string fileExtension, Stream fileStream);
|
string fileExtension, Stream fileStream);
|
||||||
|
|
||||||
Task<PaginationContainer<FileInfoDto>> GetFilesInfoAsync(int idWell,
|
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);
|
int skip, int take, CancellationToken token = default);
|
||||||
|
|
||||||
Task<FileInfoDto> GetFileInfoAsync(int fileId,
|
Task<FileInfoDto> GetFileInfoAsync(int fileId,
|
||||||
|
@ -62,8 +62,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<FileInfoDto>> GetFilesInfoAsync(int idWell,
|
public async Task<PaginationContainer<FileInfoDto>> GetFilesInfoAsync(int idWell,
|
||||||
int idCategory, DateTime begin = default, DateTime end = default,
|
int idCategory, IEnumerable<int> companies = default, DateTime begin = default,
|
||||||
int skip = 0, int take = 32, CancellationToken token = default)
|
DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var query = db.Files
|
var query = db.Files
|
||||||
.Include(f => f.Author)
|
.Include(f => f.Author)
|
||||||
@ -72,6 +72,10 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
query = query.Where(e => !e.IsDeleted);
|
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)
|
if (begin != default)
|
||||||
query = query.Where(e => e.UploadDate >= begin);
|
query = query.Where(e => e.UploadDate >= begin);
|
||||||
|
|
||||||
@ -103,6 +107,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var filePropertiesDto = item.Adapt<FileInfoDto>();
|
var filePropertiesDto = item.Adapt<FileInfoDto>();
|
||||||
filePropertiesDto.AuthorName = item.Author.Name;
|
filePropertiesDto.AuthorName = item.Author.Name;
|
||||||
|
filePropertiesDto.CompanyId = item.Author.IdCompany != null
|
||||||
|
? item.Author.Company.Id
|
||||||
|
: 0;
|
||||||
result.Items.Add(filePropertiesDto);
|
result.Items.Add(filePropertiesDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -79,6 +80,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="idCategory">id категории файла</param>
|
/// <param name="idCategory">id категории файла</param>
|
||||||
|
/// <param name="companies">id компаний для фильтрации возвращаемых файлов</param>
|
||||||
/// <param name="begin">дата начала</param>
|
/// <param name="begin">дата начала</param>
|
||||||
/// <param name="end">дата окончания</param>
|
/// <param name="end">дата окончания</param>
|
||||||
/// <param name="skip">для пагинации кол-во записей пропустить</param>
|
/// <param name="skip">для пагинации кол-во записей пропустить</param>
|
||||||
@ -89,7 +91,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[ProducesResponseType(typeof(PaginationContainer<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetFilesInfoAsync([FromRoute] int idWell,
|
public async Task<IActionResult> GetFilesInfoAsync([FromRoute] int idWell,
|
||||||
int skip = 0, int take = 32, int idCategory = default,
|
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();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var filesInfo = await fileService.GetFilesInfoAsync(idWell, idCategory,
|
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())
|
if (filesInfo is null || !filesInfo.Items.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
Loading…
Reference in New Issue
Block a user