diff --git a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs index 292a8ebe..8751a510 100644 --- a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs +++ b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs @@ -28,6 +28,8 @@ namespace AsbCloudInfrastructure.Services private readonly IEmailService emailService; private readonly IFileCategoryService fileCategoryService; + private const int FileServiceThrewException = -1; + public WellFinalDocumentsService(IAsbCloudDbContext context, IFileService fileService, IUserService userService, @@ -76,69 +78,6 @@ namespace AsbCloudInfrastructure.Services throw new ArgumentInvalidException("Данные по категориям отсутствуют."); } - public async Task GetByWellId_old(int idWell, int idUser, CancellationToken token) - { - var wellFinalDocuments = new List(); - - var wells = await context.WellFinalDocuments.Where(x => x.IdWell == idWell) - .ToListAsync(token) - .ConfigureAwait(false); - - if (wells.Any()) - { - var category = await context.FileCategories - .Where(x => wells.Select(w => w.IdCategory).Contains(x.Id)) - .ToListAsync(token) - .ConfigureAwait(false); - - var wellFinalDocs = category - .GroupJoin(wells, - fc => fc.Id, - w => w.IdCategory, - (o, i) => new { - IdCategory = o.Id, - NameCategory = o.Name, - Wells = i - }) - .ToList(); - - var wellFiles = await fileService.GetInfosByWellIdAsync(idWell, token).ConfigureAwait(false); - - wellFinalDocs.ForEach(async item => { - var userIds = item.Wells - .Select(x => x.IdUser) - .ToList(); - var allUsers = await userService.GetAllAsync(token) - .ConfigureAwait(false); - - var allFiles = wellFiles.Where(x => x.IdCategory == item.IdCategory); - - FileInfoDto? actualFile = null; - if (allFiles.Any()) - { - actualFile = allFiles.OrderByDescending(x => x.Id) - .FirstOrDefault(); - } - - var publishers = allUsers.Where(x => userIds.Contains(x.Id)); - - wellFinalDocuments.Add(new WellFinalDocumentDto { - IdCategory = item.IdCategory, - NameCategory = item.NameCategory, - Publishers = publishers, - FilesCount = allFiles.Count(), - File = actualFile, - PermissionToUpload = publishers.Any(x => x.Id == idUser) - }); - }); - } - - return new WellCaseDto { - IdWell = idWell, - WellFinalDocuments = wellFinalDocuments - }; - } - public async Task GetByWellId(int idWell, int idUser, CancellationToken token) { var entities = await context.WellFinalDocuments @@ -200,7 +139,7 @@ namespace AsbCloudInfrastructure.Services return companyIds.Contains(idCompany); }) .OrderBy(x => x.Surname) - .ToList(); + .ToArray(); } public async Task SaveCategoryFile(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token) @@ -217,7 +156,7 @@ namespace AsbCloudInfrastructure.Services var file = await fileService.SaveAsync(dto.IdWell, dto.IdUser, dto.IdCategory, fileName, fileStream, token).ConfigureAwait(false); - return file?.Id ?? -1; + return file?.Id ?? FileServiceThrewException; //TODO: изменить когда файловый сервис будет переведен на nullable } public async Task GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token) diff --git a/AsbCloudWebApi/Controllers/FileCategoryController.cs b/AsbCloudWebApi/Controllers/FileCategoryController.cs index 243ba6e7..5567c5e7 100644 --- a/AsbCloudWebApi/Controllers/FileCategoryController.cs +++ b/AsbCloudWebApi/Controllers/FileCategoryController.cs @@ -16,20 +16,6 @@ namespace AsbCloudWebApi.Controllers public FileCategoryController(ICrudService service, IFileCategoryService fileCategoryService) : base(service) { - this.fileCategoryService = fileCategoryService; - } - - /// - /// Получение справочника категорий файлов - /// - /// - [HttpGet] - [Route("/api/fileCategories")] - [Permission] - public async Task GetWellFileCategory(CancellationToken token = default) - { - var data = await fileCategoryService.GetWellCategoryAsync(token); - return Ok(data); } } } diff --git a/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs b/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs index 44891b02..12be0baf 100644 --- a/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs +++ b/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs @@ -32,19 +32,6 @@ namespace AsbCloudWebApi.Controllers this.fileCategoryService = fileCategoryService; } - /// - /// Получение справочника категорий файлов - /// - /// - [HttpGet] - [Route("fileCategories")] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetFileCategories(CancellationToken token = default) - { - var data = await fileCategoryService.GetWellCaseCategoriesAsync(token); - return Ok(data); - } - /// /// Получение всех записей /// @@ -72,7 +59,6 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet("{idWell}/availableUsers")] [Permission] - [Route("publishers")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetAvailableUsersAsync(int idWell, CancellationToken token = default) { @@ -150,11 +136,11 @@ namespace AsbCloudWebApi.Controllers /// /// [HttpGet] - [Route("/api/wellFileCategories")] + [Route("wellCaseCategories")] [Permission] - public async Task GetWellFileCategory(CancellationToken token = default) + public async Task GetWellCaseCategoriesAsync(CancellationToken token = default) { - var data = await fileCategoryService.GetWellCategoryAsync(token); + var data = await fileCategoryService.GetWellCaseCategoriesAsync(token); return Ok(data); }