forked from ddrilling/AsbCloudServer
#6385536 refactoring
This commit is contained in:
parent
8a83194187
commit
8b68b8276a
@ -39,6 +39,11 @@ namespace AsbCloudApp.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long Size { get; set; }
|
public long Size { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Помечен как удаленный
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DTO автора
|
/// DTO автора
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -14,13 +14,12 @@ namespace AsbCloudApp.Repositories
|
|||||||
public interface IFileRepository : ICrudService<FileInfoDto>
|
public interface IFileRepository : ICrudService<FileInfoDto>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить файлы определенной категории
|
/// Получение файлов по скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="idCategory"></param>
|
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token);
|
Task<IEnumerable<FileInfoDto>> GetInfosAsync(FileRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список файлов в контейнере
|
/// Получить список файлов в контейнере
|
||||||
@ -28,7 +27,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PaginationContainer<FileInfoDto>> GetInfosAsync(FileServiceRequest request, CancellationToken token = default);
|
Task<PaginationContainer<FileInfoDto>> GetInfosPaginatedAsync(FileRequest request, CancellationToken token = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Пометить файл как удаленный
|
/// Пометить файл как удаленный
|
||||||
@ -79,13 +78,6 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> MarkFileMarkAsDeletedAsync(IEnumerable<int> idsMarks, CancellationToken token);
|
Task<int> MarkFileMarkAsDeletedAsync(IEnumerable<int> idsMarks, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получение файлов по скважине
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<FileInfoDto>> GetInfosByWellIdAsync(FileServiceRequest request, CancellationToken token);
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@ namespace AsbCloudApp.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметры запроса для файлового сервиса
|
/// Параметры запроса для файлового сервиса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileServiceRequest : RequestBase
|
public class FileRequest : RequestBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Идентификатор скважины
|
/// Идентификатор скважины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required]
|
[Required]
|
||||||
public int? IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Идентификатор категории файла
|
/// Идентификатор категории файла
|
||||||
@ -24,12 +24,12 @@ namespace AsbCloudApp.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Наименование компании
|
/// Наименование компании
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? CompanyName { get; set; }
|
public string? CompanyNamePart { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Имя файла
|
/// Имя файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? FileName { get; set; }
|
public string? FileNamePart { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата начала периода
|
/// Дата начала периода
|
||||||
@ -41,16 +41,6 @@ namespace AsbCloudApp.Requests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? End { get; set; }
|
public DateTime? End { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Идентификатор файла
|
|
||||||
/// </summary>
|
|
||||||
public int? IdFile { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Идентификатор отметки
|
|
||||||
/// </summary>
|
|
||||||
public int? IdMark { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Признак удаления
|
/// Признак удаления
|
||||||
/// </summary>
|
/// </summary>
|
@ -6,8 +6,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static Npgsql.PostgresTypes.PostgresCompositeType;
|
|
||||||
using static System.Net.WebRequestMethods;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
@ -41,7 +39,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="srcFilePath"></param>
|
/// <param name="srcFilePath"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory,
|
public async Task<FileInfoDto?> MoveAsync(int idWell, int? idUser, int idCategory,
|
||||||
string destinationFileName, string srcFilePath, CancellationToken token = default)
|
string destinationFileName, string srcFilePath, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
destinationFileName = Path.GetFileName(destinationFileName);
|
destinationFileName = Path.GetFileName(destinationFileName);
|
||||||
@ -61,8 +59,8 @@ namespace AsbCloudApp.Services
|
|||||||
|
|
||||||
string filePath = fileStorageRepository.MakeFilePath(idWell, idCategory, destinationFileName, fileId);
|
string filePath = fileStorageRepository.MakeFilePath(idWell, idCategory, destinationFileName, fileId);
|
||||||
fileStorageRepository.MoveFile(srcFilePath, filePath);
|
fileStorageRepository.MoveFile(srcFilePath, filePath);
|
||||||
|
|
||||||
return await GetInfoAsync(fileId, token);
|
return await GetOrDefaultAsync(fileId, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -75,7 +73,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="fileStream"></param>
|
/// <param name="fileStream"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory,
|
public async Task<FileInfoDto?> SaveAsync(int idWell, int? idUser, int idCategory,
|
||||||
string fileFullName, Stream fileStream, CancellationToken token)
|
string fileFullName, Stream fileStream, CancellationToken token)
|
||||||
{
|
{
|
||||||
//save info to db
|
//save info to db
|
||||||
@ -85,7 +83,7 @@ namespace AsbCloudApp.Services
|
|||||||
IdAuthor = idUser,
|
IdAuthor = idUser,
|
||||||
IdCategory = idCategory,
|
IdCategory = idCategory,
|
||||||
Name = Path.GetFileName(fileFullName),
|
Name = Path.GetFileName(fileFullName),
|
||||||
Size = fileStream?.Length ?? 0
|
Size = fileStream.Length
|
||||||
};
|
};
|
||||||
|
|
||||||
var fileId = await fileRepository.InsertAsync(dto, token)
|
var fileId = await fileRepository.InsertAsync(dto, token)
|
||||||
@ -95,26 +93,7 @@ namespace AsbCloudApp.Services
|
|||||||
string filePath = fileStorageRepository.MakeFilePath(idWell, idCategory, fileFullName, fileId);
|
string filePath = fileStorageRepository.MakeFilePath(idWell, idCategory, fileFullName, fileId);
|
||||||
await fileStorageRepository.SaveFileAsync(filePath, fileStream, token);
|
await fileStorageRepository.SaveFileAsync(filePath, fileStream, token);
|
||||||
|
|
||||||
return await GetInfoAsync(fileId, token);
|
return await GetOrDefaultAsync(fileId, token);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Инфо о файле
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idFile"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<FileInfoDto> GetInfoAsync(int idFile,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
var dto = await fileRepository.GetOrDefaultAsync(idFile, token).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var ext = Path.GetExtension(dto.Name);
|
|
||||||
|
|
||||||
var relativePath = GetUrl(dto.IdWell, dto.IdCategory, dto.Id, ext);
|
|
||||||
var fullPath = Path.GetFullPath(relativePath);
|
|
||||||
|
|
||||||
return dto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -198,15 +177,23 @@ namespace AsbCloudApp.Services
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить файлы определенной категории
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<IEnumerable<FileInfoDto>> GetInfosAsync(FileRequest request, CancellationToken token)
|
||||||
|
=> fileRepository.GetInfosAsync(request, token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список файлов в контейнере
|
/// Получить список файлов в контейнере
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<PaginationContainer<FileInfoDto>> GetInfosAsync(FileServiceRequest request, CancellationToken token)
|
public Task<PaginationContainer<FileInfoDto>> GetInfosPaginatedAsync(FileRequest request, CancellationToken token)
|
||||||
=> await fileRepository.GetInfosAsync(request, token)
|
=> fileRepository.GetInfosPaginatedAsync(request, token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Пометить файл как удаленный
|
/// Пометить файл как удаленный
|
||||||
@ -214,9 +201,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idFile"></param>
|
/// <param name="idFile"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> MarkAsDeletedAsync(int idFile, CancellationToken token = default)
|
public Task<int> MarkAsDeletedAsync(int idFile, CancellationToken token = default)
|
||||||
=> await fileRepository.MarkAsDeletedAsync(idFile, token)
|
=> fileRepository.MarkAsDeletedAsync(idFile, token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// добавить метку на файл
|
/// добавить метку на файл
|
||||||
@ -225,9 +211,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idUser"></param>
|
/// <param name="idUser"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> CreateFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token)
|
public Task<int> CreateFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token)
|
||||||
=> await fileRepository.CreateFileMarkAsync(fileMarkDto, idUser, token)
|
=> fileRepository.CreateFileMarkAsync(fileMarkDto, idUser, token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить запись по id
|
/// Получить запись по id
|
||||||
@ -235,9 +220,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<FileInfoDto> GetOrDefaultAsync(int id, CancellationToken token)
|
public Task<FileInfoDto?> GetOrDefaultAsync(int id, CancellationToken token)
|
||||||
=> await fileRepository.GetOrDefaultAsync(id, token)
|
=> fileRepository.GetOrDefaultAsync(id, token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить инфо о файле по метке
|
/// получить инфо о файле по метке
|
||||||
@ -245,9 +229,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idMark"></param>
|
/// <param name="idMark"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<FileInfoDto> GetByMarkId(int idMark, CancellationToken token)
|
public Task<FileInfoDto> GetByMarkId(int idMark, CancellationToken token)
|
||||||
=> await fileRepository.GetByMarkId(idMark, token)
|
=> fileRepository.GetByMarkId(idMark, token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить инфо о файле по метке
|
/// получить инфо о файле по метке
|
||||||
@ -255,30 +238,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idsMarks"></param>
|
/// <param name="idsMarks"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> MarkFileMarkAsDeletedAsync(IEnumerable<int> idsMarks, CancellationToken token)
|
public Task<int> MarkFileMarkAsDeletedAsync(IEnumerable<int> idsMarks, CancellationToken token)
|
||||||
=> await fileRepository.MarkFileMarkAsDeletedAsync(idsMarks, token)
|
=> fileRepository.MarkFileMarkAsDeletedAsync(idsMarks, token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получение файлов по скважине
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetInfosByWellIdAsync(int idWell, CancellationToken token)
|
|
||||||
=> await fileRepository.GetInfosByWellIdAsync(new FileServiceRequest { IdWell = idWell, IsDeleted = false }, token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить файлы определенной категории
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idCategory"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token)
|
|
||||||
=> await fileRepository.GetInfosByCategoryAsync(idWell, idCategory, token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление всех файлов по скважине помеченных как удаленные
|
/// Удаление всех файлов по скважине помеченных как удаленные
|
||||||
@ -288,8 +249,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> DeleteFilesFromDbMarkedDeletionByIdWell(int idWell, CancellationToken token)
|
public async Task<int> DeleteFilesFromDbMarkedDeletionByIdWell(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var files = await fileRepository.GetInfosByWellIdAsync(
|
var files = await fileRepository.GetInfosAsync(
|
||||||
new FileServiceRequest
|
new FileRequest
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
IsDeleted = true
|
IsDeleted = true
|
||||||
@ -306,8 +267,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
public async Task<int> DeleteFilesNotExistStorage(int idWell, CancellationToken token)
|
public async Task<int> DeleteFilesNotExistStorage(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var files = await fileRepository.GetInfosByWellIdAsync(
|
var files = await fileRepository.GetInfosAsync(
|
||||||
new FileServiceRequest
|
new FileRequest
|
||||||
{
|
{
|
||||||
IdWell = idWell
|
IdWell = idWell
|
||||||
},
|
},
|
||||||
@ -324,8 +285,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetListFilesNotDisc(int idWell, CancellationToken token)
|
public async Task<IEnumerable<FileInfoDto>> GetListFilesNotDisc(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var files = await fileRepository.GetInfosByWellIdAsync(
|
var files = await fileRepository.GetInfosAsync(
|
||||||
new FileServiceRequest
|
new FileRequest
|
||||||
{
|
{
|
||||||
IdWell = idWell
|
IdWell = idWell
|
||||||
},
|
},
|
||||||
@ -338,9 +299,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// Получить файловый поток по идентификатору файла
|
/// Получить файловый поток по идентификатору файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileInfo"></param>
|
/// <param name="fileInfo"></param>
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public FileStream GetFileStream(FileInfoDto fileInfo)
|
public Stream GetFileStream(FileInfoDto fileInfo)
|
||||||
{
|
{
|
||||||
var relativePath = GetUrl(fileInfo);
|
var relativePath = GetUrl(fileInfo);
|
||||||
var fileStream = new FileStream(Path.GetFullPath(relativePath), FileMode.Open);
|
var fileStream = new FileStream(Path.GetFullPath(relativePath), FileMode.Open);
|
||||||
|
@ -117,6 +117,17 @@ namespace AsbCloudDb
|
|||||||
}
|
}
|
||||||
return stat;
|
return stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IQueryable<T> SkipTake<T>(this IQueryable<T> query, int? skip, int? take)
|
||||||
|
{
|
||||||
|
if (skip > 0)
|
||||||
|
query = query.Skip((int)skip);
|
||||||
|
|
||||||
|
if (take > 0)
|
||||||
|
query = query.Take((int)take);
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IQueryStringFactory { }
|
interface IQueryStringFactory { }
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services;
|
||||||
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Org.BouncyCastle.Asn1.Ocsp;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -16,7 +21,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
public class FileRepository : IFileRepository
|
public class FileRepository : IFileRepository
|
||||||
{
|
{
|
||||||
private readonly IQueryable<AsbCloudDb.Model.FileInfo> dbSetConfigured;
|
private readonly IQueryable<FileInfo> dbSetConfigured;
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
|
|
||||||
public FileRepository(IAsbCloudDbContext db)
|
public FileRepository(IAsbCloudDbContext db)
|
||||||
@ -31,10 +36,55 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.Include(f => f.Well);
|
.Include(f => f.Well);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token)
|
private IQueryable<FileInfo> BuildQuery(FileRequest request)
|
||||||
{
|
{
|
||||||
var entities = await dbSetConfigured
|
var query = dbSetConfigured
|
||||||
.Where(e => e.IdWell == idWell && e.IdCategory == idCategory && e.IsDeleted == false)
|
.Where(e => e.IdWell == request.IdWell);
|
||||||
|
|
||||||
|
double timezoneOffsetHours = query.FirstOrDefault()
|
||||||
|
?.Well.Timezone.Hours ?? 5d;
|
||||||
|
|
||||||
|
if (request.IdCategory is not null)
|
||||||
|
query = query.Where(x => x.IdCategory == request.IdCategory);
|
||||||
|
|
||||||
|
if (request.IsDeleted is not null)
|
||||||
|
query = query.Where(x => x.IsDeleted == request.IsDeleted);
|
||||||
|
|
||||||
|
if (request.CompanyNamePart is not null)
|
||||||
|
query = query.Where(e => e.Author.Company.Caption.ToLower().Contains(request.CompanyNamePart.ToLower()));
|
||||||
|
|
||||||
|
if (request.FileNamePart is not null)
|
||||||
|
query = query.Where(e => e.Name.ToLower().Contains(request.FileNamePart.ToLower()));
|
||||||
|
|
||||||
|
if (request.Begin is not null)
|
||||||
|
{
|
||||||
|
var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezoneOffsetHours);
|
||||||
|
query = query.Where(e => e.UploadDate >= beginUtc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.End is not null)
|
||||||
|
{
|
||||||
|
var endUtc = request.End.Value.ToUtcDateTimeOffset(timezoneOffsetHours);
|
||||||
|
query = query.Where(e => e.UploadDate <= endUtc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request?.SortFields?.Any() == true)
|
||||||
|
{
|
||||||
|
query = query.SortBy(request.SortFields);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
query = query
|
||||||
|
.OrderBy(o => o.UploadDate);
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<FileInfoDto>> GetInfosAsync(FileRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
|
||||||
|
var entities = await query
|
||||||
|
.SkipTake(request.Skip, request.Take)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
@ -43,51 +93,37 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<FileInfoDto>> GetInfosAsync(FileServiceRequest request, CancellationToken token = default)
|
public async Task<PaginationContainer<FileInfoDto>> GetInfosPaginatedAsync(FileRequest request, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var query = GetQuery(request, token);
|
|
||||||
var firstFile = query.FirstOrDefault();
|
|
||||||
var skip = request.Skip ?? 0;
|
var skip = request.Skip ?? 0;
|
||||||
var take = request.Take ?? 32;
|
var take = request.Take ?? 32;
|
||||||
|
|
||||||
if (firstFile is null)
|
var query = BuildQuery(request);
|
||||||
return new PaginationContainer<FileInfoDto>()
|
|
||||||
{
|
|
||||||
Skip = skip,
|
|
||||||
Take = take,
|
|
||||||
Count = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
var timezoneOffset = firstFile.Well.Timezone?.Hours ?? 5;
|
var result = new PaginationContainer<FileInfoDto>()
|
||||||
var count = await query.CountAsync(token).ConfigureAwait(false);
|
|
||||||
var result = new PaginationContainer<FileInfoDto>(count)
|
|
||||||
{
|
{
|
||||||
Skip = skip,
|
Skip = skip,
|
||||||
Take = take,
|
Take = take,
|
||||||
Count = count,
|
Count = await query.CountAsync(token),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (count <= skip)
|
if (result.Count == 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
query = query.OrderBy(e => e.UploadDate);
|
|
||||||
|
|
||||||
if (skip > 0)
|
|
||||||
query = query.Skip(skip);
|
|
||||||
query = query.Take(take);
|
|
||||||
|
|
||||||
var entities = await query
|
var entities = await query
|
||||||
.Take(take).AsNoTracking().ToListAsync(token)
|
.SkipTake(skip, take)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var dtos = entities.Select(e => Convert(e, timezoneOffset));
|
result.Items = entities.Select(e => Convert(e)).ToList();
|
||||||
result.Items.AddRange(dtos);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetInfoByIdsAsync(IEnumerable<int> idsFile, CancellationToken token)
|
public async Task<IEnumerable<FileInfoDto>> GetInfoByIdsAsync(IEnumerable<int> idsFile, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = new List<FileInfoDto>();
|
var result = Enumerable.Empty<FileInfoDto>();
|
||||||
|
|
||||||
var entities = await dbSetConfigured
|
var entities = await dbSetConfigured
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@ -95,14 +131,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
foreach (var entity in entities)
|
if (entities is not null)
|
||||||
{
|
result = entities.Select(entity => Convert(entity));
|
||||||
if (entity is null)
|
|
||||||
{
|
|
||||||
throw new FileNotFoundException($"fileId:{entity.Id} not found");
|
|
||||||
}
|
|
||||||
result.Add(Convert(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -140,7 +170,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.FirstOrDefaultAsync(f => f.FileMarks.Any(m => m.Id == idMark), token)
|
.FirstOrDefaultAsync(f => f.FileMarks.Any(m => m.Id == idMark), token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
FileInfoDto dto = Convert(entity);
|
FileInfoDto dto = Convert(entity!);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,26 +208,13 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return await db.SaveChangesAsync(token);
|
return await db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetInfosByWellIdAsync(FileServiceRequest request, CancellationToken token)
|
|
||||||
{
|
|
||||||
var query = GetQuery(request, token);
|
|
||||||
|
|
||||||
var entities = await query
|
|
||||||
.AsNoTracking()
|
|
||||||
.ToListAsync(token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
var dtos = entities.Select(e => Convert(e));
|
|
||||||
return dtos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<FileInfoDto>> GetAllAsync(CancellationToken token)
|
public async Task<IEnumerable<FileInfoDto>> GetAllAsync(CancellationToken token)
|
||||||
=> await dbSetConfigured.AsNoTracking()
|
=> await dbSetConfigured.AsNoTracking()
|
||||||
.Select(x => Convert(x))
|
.Select(x => Convert(x))
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
public async Task<FileInfoDto> GetOrDefaultAsync(int id, CancellationToken token)
|
public async Task<FileInfoDto?> GetOrDefaultAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = await dbSetConfigured
|
var entity = await dbSetConfigured
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@ -205,24 +222,20 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (entity is null)
|
if (entity is null)
|
||||||
{
|
return null;
|
||||||
throw new FileNotFoundException($"fileId:{id} not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dto = Convert(entity);
|
var dto = Convert(entity);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileInfoDto GetOrDefault(int id)
|
public FileInfoDto? GetOrDefault(int id)
|
||||||
{
|
{
|
||||||
var entity = dbSetConfigured
|
var entity = dbSetConfigured
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.FirstOrDefault(f => f.Id == id);
|
.FirstOrDefault(f => f.Id == id);
|
||||||
|
|
||||||
if (entity is null)
|
if (entity is null)
|
||||||
{
|
return null;
|
||||||
throw new FileNotFoundException($"fileId:{id} not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dto = Convert(entity);
|
var dto = Convert(entity);
|
||||||
return dto;
|
return dto;
|
||||||
@ -230,7 +243,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
public async Task<int> InsertAsync(FileInfoDto newItem, CancellationToken token)
|
public async Task<int> InsertAsync(FileInfoDto newItem, CancellationToken token)
|
||||||
{
|
{
|
||||||
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
var fileInfo = new FileInfo()
|
||||||
{
|
{
|
||||||
IdWell = newItem.IdWell,
|
IdWell = newItem.IdWell,
|
||||||
IdAuthor = newItem.IdAuthor,
|
IdAuthor = newItem.IdAuthor,
|
||||||
@ -261,50 +274,13 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<AsbCloudDb.Model.FileInfo> GetQuery(FileServiceRequest request, CancellationToken token = default)
|
private static FileInfoDto Convert(FileInfo entity)
|
||||||
{
|
|
||||||
var query = dbSetConfigured
|
|
||||||
.Where(e => e.IdWell == request.IdWell &&
|
|
||||||
e.IdCategory == request.IdCategory);
|
|
||||||
|
|
||||||
if (request.IsDeleted is not null)
|
|
||||||
query = query.Where(x => x.IsDeleted == request.IsDeleted);
|
|
||||||
|
|
||||||
if (request.CompanyName is not null)
|
|
||||||
query = query.Where(e => (e.Author == null) ||
|
|
||||||
(e.Author.Company == null) ||
|
|
||||||
e.Author.Company.Caption.Contains(request.CompanyName));
|
|
||||||
|
|
||||||
if (request.FileName is not null)
|
|
||||||
query = query.Where(e => e.Name.ToLower().Contains(request.FileName.ToLower()));
|
|
||||||
|
|
||||||
var firstFile = query.FirstOrDefault();
|
|
||||||
if (firstFile is null)
|
|
||||||
return Enumerable.Empty<AsbCloudDb.Model.FileInfo>().AsQueryable();
|
|
||||||
|
|
||||||
var timezoneOffset = firstFile.Well.Timezone?.Hours ?? 5;
|
|
||||||
if (request.Begin is not null)
|
|
||||||
{
|
|
||||||
var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezoneOffset);
|
|
||||||
query = query.Where(e => e.UploadDate >= beginUtc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.End is not null)
|
|
||||||
{
|
|
||||||
var endUtc = request.End.Value.ToUtcDateTimeOffset(timezoneOffset);
|
|
||||||
query = query.Where(e => e.UploadDate <= endUtc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static FileInfoDto Convert(AsbCloudDb.Model.FileInfo entity)
|
|
||||||
{
|
{
|
||||||
var timezoneOffset = entity.Well.Timezone?.Hours ?? 5;
|
var timezoneOffset = entity.Well.Timezone?.Hours ?? 5;
|
||||||
return Convert(entity, timezoneOffset);
|
return Convert(entity, timezoneOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileInfoDto Convert(AsbCloudDb.Model.FileInfo entity, double timezoneOffset)
|
private static FileInfoDto Convert(FileInfo entity, double timezoneOffset)
|
||||||
{
|
{
|
||||||
var dto = entity.Adapt<FileInfoDto>();
|
var dto = entity.Adapt<FileInfoDto>();
|
||||||
dto.UploadDate = entity.UploadDate.ToRemoteDateTime(timezoneOffset);
|
dto.UploadDate = entity.UploadDate.ToRemoteDateTime(timezoneOffset);
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Exceptions;
|
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FileInfo = System.IO.FileInfo;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository
|
namespace AsbCloudInfrastructure.Repository
|
||||||
{
|
{
|
||||||
@ -102,10 +99,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
var allFilesPath = GetFilesPath(idWell);
|
var allFilesPath = GetFilesPath(idWell);
|
||||||
|
|
||||||
foreach (var filePath in allFilesPath)
|
foreach (var filePath in allFilesPath)
|
||||||
{
|
if(int.TryParse(Path.GetFileNameWithoutExtension(filePath), out int idFile))
|
||||||
int.TryParse(Path.GetFileNameWithoutExtension(filePath), out int idFile);
|
result.Add(idFile);
|
||||||
result.Add(idFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -118,7 +113,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
private static void CreateDirectory(string filePath)
|
private static void CreateDirectory(string filePath)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
var directoryName = Path.GetDirectoryName(filePath)!;
|
||||||
|
Directory.CreateDirectory(directoryName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
@ -282,7 +282,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
fileMarkDto.IdMarkType != idMarkTypeReject)
|
fileMarkDto.IdMarkType != idMarkTypeReject)
|
||||||
throw new ArgumentInvalidException($"В этом методе допустимы только отметки о принятии или отклонении.", nameof(fileMarkDto));
|
throw new ArgumentInvalidException($"В этом методе допустимы только отметки о принятии или отклонении.", nameof(fileMarkDto));
|
||||||
|
|
||||||
var fileInfo = await fileService.GetInfoAsync(fileMarkDto.IdFile, token)
|
var fileInfo = await fileService.GetOrDefaultAsync(fileMarkDto.IdFile, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
@ -357,7 +357,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
|
|
||||||
private async Task NotifyPublisherOnFullAccepAsync(FileMarkDto fileMark, CancellationToken token)
|
private async Task NotifyPublisherOnFullAccepAsync(FileMarkDto fileMark, CancellationToken token)
|
||||||
{
|
{
|
||||||
var file = await fileService.GetInfoAsync(fileMark.IdFile, token);
|
var file = await fileService.GetOrDefaultAsync(fileMark.IdFile, token);
|
||||||
var well = await wellService.GetOrDefaultAsync(file.IdWell, token);
|
var well = await wellService.GetOrDefaultAsync(file.IdWell, token);
|
||||||
var user = file.Author;
|
var user = file.Author;
|
||||||
var factory = new DrillingMailBodyFactory(configuration);
|
var factory = new DrillingMailBodyFactory(configuration);
|
||||||
@ -369,7 +369,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
|
|
||||||
private async Task NotifyPublisherOnRejectAsync(FileMarkDto fileMark, CancellationToken token)
|
private async Task NotifyPublisherOnRejectAsync(FileMarkDto fileMark, CancellationToken token)
|
||||||
{
|
{
|
||||||
var file = await fileService.GetInfoAsync(fileMark.IdFile, token);
|
var file = await fileService.GetOrDefaultAsync(fileMark.IdFile, token);
|
||||||
var well = await wellService.GetOrDefaultAsync(file.IdWell, token);
|
var well = await wellService.GetOrDefaultAsync(file.IdWell, token);
|
||||||
var user = file.Author;
|
var user = file.Author;
|
||||||
var factory = new DrillingMailBodyFactory(configuration);
|
var factory = new DrillingMailBodyFactory(configuration);
|
||||||
@ -473,7 +473,6 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||||
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
||||||
var mailService = new EmailService(backgroundWorker, configuration);
|
|
||||||
async Task funcProgramMake(string id, CancellationToken token)
|
async Task funcProgramMake(string id, CancellationToken token)
|
||||||
{
|
{
|
||||||
var contextOptions = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
var contextOptions = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Repository;
|
using AsbCloudInfrastructure.Repository;
|
||||||
@ -96,7 +97,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.Select(g => g.Key);
|
.Select(g => g.Key);
|
||||||
|
|
||||||
var files = (await fileService
|
var files = (await fileService
|
||||||
.GetInfosByWellIdAsync(idWell, token)
|
.GetInfosAsync(new FileRequest { IdWell = idWell}, token)
|
||||||
.ConfigureAwait(false))
|
.ConfigureAwait(false))
|
||||||
.Where(f => categoriesIds.Contains(f.IdCategory))
|
.Where(f => categoriesIds.Contains(f.IdCategory))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
@ -162,7 +163,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public async Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token)
|
public async Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token)
|
||||||
{
|
{
|
||||||
var files = await fileService.GetInfosByCategoryAsync(idWell, idCategory, token).ConfigureAwait(false);
|
var request = new FileRequest
|
||||||
|
{
|
||||||
|
IdWell = idWell,
|
||||||
|
IdCategory = idCategory,
|
||||||
|
};
|
||||||
|
var files = await fileService.GetInfosAsync(request, token).ConfigureAwait(false);
|
||||||
|
|
||||||
return new WellFinalDocumentsHistoryDto {
|
return new WellFinalDocumentsHistoryDto {
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
|
@ -220,7 +220,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
{
|
{
|
||||||
ConfigureNotApproved();
|
ConfigureNotApproved();
|
||||||
fileServiceMock
|
fileServiceMock
|
||||||
.Setup(s => s.GetInfoAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
.Setup(s => s.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||||
.Returns(Task.FromResult(file1002.Adapt<FileInfoDto>()));
|
.Returns(Task.FromResult(file1002.Adapt<FileInfoDto>()));
|
||||||
|
|
||||||
fileServiceMock
|
fileServiceMock
|
||||||
@ -251,7 +251,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
{
|
{
|
||||||
ConfigureNotApproved();
|
ConfigureNotApproved();
|
||||||
fileServiceMock
|
fileServiceMock
|
||||||
.Setup(s => s.GetInfoAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
.Setup(s => s.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||||
.Returns(Task.FromResult(file1002.Adapt<FileInfoDto>()));
|
.Returns(Task.FromResult(file1002.Adapt<FileInfoDto>()));
|
||||||
|
|
||||||
fileServiceMock
|
fileServiceMock
|
||||||
|
@ -109,18 +109,12 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
return Task.FromResult(result);
|
return Task.FromResult(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
repositoryMock.Setup(x => x.GetInfosByWellIdAsync(It.IsAny<FileServiceRequest>(), It.IsAny<CancellationToken>()))
|
repositoryMock.Setup(x => x.GetInfosAsync(It.IsAny<FileRequest>(), It.IsAny<CancellationToken>()))
|
||||||
.Returns((FileServiceRequest request, CancellationToken token) => {
|
.Returns((FileRequest request, CancellationToken token) => {
|
||||||
var data = Files.Where(x => x.IdWell == request.IdWell);
|
var data = Files.Where(x => x.IdWell == request.IdWell);
|
||||||
return Task.FromResult(data);
|
return Task.FromResult(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
repositoryMock.Setup(x => x.GetInfosByCategoryAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
|
||||||
.Returns((int idWell, int idCategory, CancellationToken token) => {
|
|
||||||
var data = Files.Where(x => x.IdWell == idWell && x.IdCategory == idCategory);
|
|
||||||
return Task.FromResult(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
repositoryMock.Setup(x => x.CreateFileMarkAsync(It.IsAny<FileMarkDto>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
repositoryMock.Setup(x => x.CreateFileMarkAsync(It.IsAny<FileMarkDto>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||||
.Returns((FileMarkDto dto, int idUser, CancellationToken token) => {
|
.Returns((FileMarkDto dto, int idUser, CancellationToken token) => {
|
||||||
dto.Id = FileMarks.Max(x => x.Id) + 1;
|
dto.Id = FileMarks.Max(x => x.Id) + 1;
|
||||||
@ -149,9 +143,9 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetInfoAsync_returns_FileInfo()
|
public async Task GetOrDefaultAsync_returns_FileInfo()
|
||||||
{
|
{
|
||||||
var data = await fileService.GetInfoAsync(1742, CancellationToken.None);
|
var data = await fileService.GetOrDefaultAsync(1742, CancellationToken.None);
|
||||||
Assert.NotNull(data);
|
Assert.NotNull(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,20 +185,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
Assert.True(result > 0);
|
Assert.True(result > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetInfosByWellIdAsync_returns_FileInfo()
|
|
||||||
{
|
|
||||||
var data = await fileService.GetInfosByWellIdAsync(90, CancellationToken.None);
|
|
||||||
Assert.NotNull(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetInfosByCategoryAsync_returns_FileInfo()
|
|
||||||
{
|
|
||||||
var data = await fileService.GetInfosByCategoryAsync(90, 10040, CancellationToken.None);
|
|
||||||
Assert.NotNull(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CreateFileMarkAsync()
|
public async Task CreateFileMarkAsync()
|
||||||
{
|
{
|
||||||
|
@ -7,8 +7,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Text;
|
using AsbCloudDb.Model;
|
||||||
using static System.Net.WebRequestMethods;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -79,19 +78,19 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetFilesInfoAsync(
|
public async Task<IActionResult> GetFilesInfoAsync(
|
||||||
[FromQuery] FileServiceRequest request,
|
[FromQuery] FileRequest request,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (request.IdWell is null || request.IdCategory is null || idCompany is null)
|
if (request.IdCategory is null || idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value,
|
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value,
|
||||||
request.IdWell.Value, token).ConfigureAwait(false))
|
request.IdWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var filesInfo = await fileService.GetInfosAsync(request, token).ConfigureAwait(false);
|
var filesInfo = await fileService.GetInfosPaginatedAsync(request, token).ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(filesInfo);
|
return Ok(filesInfo);
|
||||||
}
|
}
|
||||||
@ -100,36 +99,33 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// Возвращает файл с диска на сервере
|
/// Возвращает файл с диска на сервере
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="fileId">id запрашиваемого файла</param>
|
/// <param name="idFile">id запрашиваемого файла</param>
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
/// <returns>Запрашиваемый файл</returns>
|
/// <returns>Запрашиваемый файл</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{fileId}")]
|
[Route("{idFile}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetFileAsync([FromRoute] int idWell,
|
public async Task<IActionResult> GetFileAsync([FromRoute] int idWell,
|
||||||
int fileId, CancellationToken token = default)
|
int idFile, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
|
var fileInfo = await fileService.GetOrDefaultAsync(idFile, token);
|
||||||
|
|
||||||
|
if (fileInfo is null)
|
||||||
|
return NotFound(idFile);
|
||||||
|
|
||||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
idWell, token).ConfigureAwait(false))
|
fileInfo.IdWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
try
|
var fileStream = fileService.GetFileStream(fileInfo);
|
||||||
{
|
|
||||||
var fileInfo = await fileService.GetInfoAsync(fileId, token);
|
|
||||||
var fileStream = fileService.GetFileStream(fileInfo);
|
|
||||||
|
|
||||||
return File(fileStream, "application/octet-stream", fileInfo.Name);
|
return File(fileStream, "application/octet-stream", fileInfo.Name);
|
||||||
}
|
|
||||||
catch (FileNotFoundException ex)
|
|
||||||
{
|
|
||||||
return NotFound(ex.FileName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -151,13 +147,16 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
if (idUser is null || idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
idWell, token).ConfigureAwait(false))
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var file = await fileService.GetInfoAsync((int)idFile, token);
|
var fileInfo = await fileService.GetOrDefaultAsync(idFile, token);
|
||||||
|
|
||||||
if (!userService.HasPermission((int)idUser, $"File.edit{file.IdCategory}"))
|
if (fileInfo is null)
|
||||||
|
return NotFound(idFile);
|
||||||
|
|
||||||
|
if (!userService.HasPermission((int)idUser, $"File.edit{fileInfo?.IdCategory}"))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await fileService.MarkAsDeletedAsync(idFile, token);
|
var result = await fileService.MarkAsDeletedAsync(idFile, token);
|
||||||
|
Loading…
Reference in New Issue
Block a user