diff --git a/AsbCloudApp/Services/IFileCategoryService.cs b/AsbCloudApp/Services/IFileCategoryService.cs
index 01710c8e..70441331 100644
--- a/AsbCloudApp/Services/IFileCategoryService.cs
+++ b/AsbCloudApp/Services/IFileCategoryService.cs
@@ -16,6 +16,6 @@ namespace AsbCloudApp.Services
/// Получение справочника категорий файлов
///
///
- Task> GetWellCategoryAsync(CancellationToken token);
+ Task> GetWellCaseCategoriesAsync(CancellationToken token);
}
}
diff --git a/AsbCloudInfrastructure/Services/FileCategoryService.cs b/AsbCloudInfrastructure/Services/FileCategoryService.cs
index c37a3885..3bb8326e 100644
--- a/AsbCloudInfrastructure/Services/FileCategoryService.cs
+++ b/AsbCloudInfrastructure/Services/FileCategoryService.cs
@@ -2,8 +2,6 @@
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
-using DocumentFormat.OpenXml.InkML;
-using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -13,37 +11,21 @@ namespace AsbCloudInfrastructure.Services
{
public class FileCategoryService : CrudCacheServiceBase, IFileCategoryService
{
- private readonly IAsbCloudDbContext db;
-
public FileCategoryService(IAsbCloudDbContext context)
: base(context)
{
- this.db = context;
}
- public async Task> GetWellCategoryAsync(CancellationToken token)
+ public async Task> GetWellCaseCategoriesAsync(CancellationToken token)
{
- var data = await (from category in db.FileCategories
- where category.Id >= 10000 && category.Id <= 20000
- select new FileCategoryDto
- {
- Id = category.Id,
- Name = category.Name,
- ShortName = category.ShortName
- })
- .ToListAsync(token)
- .ConfigureAwait(false);
+ var cache = await GetCacheAsync(token)
+ .ConfigureAwait(false);
+ var dtos = cache
+ .Where(kv => kv.Key >= 10000)
+ .Where(kv => kv.Key <= 20000)
+ .Select(kv => kv.Value);
- return data.ToList();
- }
-
- public override async Task GetOrDefaultAsync(int id, CancellationToken token)
- {
- var entity = await db.FileCategories
- .FirstOrDefaultAsync(x => x.Id == id)
- .ConfigureAwait(false);
- var dto = Convert(entity);
- return dto;
+ return dtos;
}
}
}
diff --git a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs
index 1da7f0a9..292a8ebe 100644
--- a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs
+++ b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs
@@ -2,7 +2,6 @@
using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
-using AsbCloudInfrastructure.Repository;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -77,7 +76,7 @@ namespace AsbCloudInfrastructure.Services
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
}
- public async Task GetByWellId(int idWell, int idUser, CancellationToken token)
+ public async Task GetByWellId_old(int idWell, int idUser, CancellationToken token)
{
var wellFinalDocuments = new List();
@@ -140,6 +139,52 @@ namespace AsbCloudInfrastructure.Services
};
}
+ public async Task GetByWellId(int idWell, int idUser, CancellationToken token)
+ {
+ var entities = await context.WellFinalDocuments
+ .Include(d => d.Category)
+ .Include(d => d.User)
+ .Where(d => d.IdWell == idWell)
+ .AsNoTracking()
+ .ToArrayAsync(token)
+ .ConfigureAwait(false);
+
+ var entitiesGroups = entities
+ .GroupBy(d => d.Category);
+
+ var categoriesIds = entitiesGroups
+ .Select(g => g.Key.Id);
+
+ var files = (await fileService
+ .GetInfosByWellIdAsync(idWell, token)
+ .ConfigureAwait(false))
+ .Where(f => categoriesIds.Contains(f.IdCategory))
+ .ToArray();
+
+ var docs = entitiesGroups.Select((g) => new WellFinalDocumentDto
+ {
+ IdCategory = g.Key.Id,
+ FilesCount = files
+ .Where(f => f.IdCategory == g.Key.Id)
+ .Count(),
+ File = files
+ .Where(f => f.IdCategory == g.Key.Id)
+ .OrderBy(f => f.UploadDate)
+ .LastOrDefault(),
+ NameCategory = g.Key.Name,
+ Publishers = g.Select(i => i.User.Adapt()),
+ PermissionToUpload = g.Any(i => i.IdUser == idUser),
+ });
+
+ var result = new WellCaseDto
+ {
+ IdWell = idWell,
+ PermissionToSetPubliher = userService.HasPermission(idUser, "WellFinalDocument.editPublisher"),
+ WellFinalDocuments = docs,
+ };
+ return result;
+ }
+
public async Task> GetAvailableUsersAsync(int idWell, CancellationToken token)
{
var companyIds = await context.RelationCompaniesWells
diff --git a/AsbCloudWebApi.Tests/ServicesTests/FileCategoryServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/FileCategoryServiceTest.cs
index 196a0547..620261c5 100644
--- a/AsbCloudWebApi.Tests/ServicesTests/FileCategoryServiceTest.cs
+++ b/AsbCloudWebApi.Tests/ServicesTests/FileCategoryServiceTest.cs
@@ -29,7 +29,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetWellCategoryAsync_return_cnt_file_category()
{
- var cnt = (await service.GetWellCategoryAsync(CancellationToken.None)).Count();
+ var cnt = (await service.GetWellCaseCategoriesAsync(CancellationToken.None)).Count();
Assert.NotEqual(0, cnt);
}
}
diff --git a/AsbCloudWebApi/Controllers/FileCategoryController.cs b/AsbCloudWebApi/Controllers/FileCategoryController.cs
index 05ec370c..7e86276d 100644
--- a/AsbCloudWebApi/Controllers/FileCategoryController.cs
+++ b/AsbCloudWebApi/Controllers/FileCategoryController.cs
@@ -2,9 +2,6 @@
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using System.Threading.Tasks;
-using System.Threading;
-using System.Collections.Generic;
namespace AsbCloudWebApi.Controllers
{
@@ -16,24 +13,9 @@ namespace AsbCloudWebApi.Controllers
[Authorize]
public class FileCategoryController : CrudController>
{
- private readonly IFileCategoryService fileCategoryService;
public FileCategoryController(ICrudService service, IFileCategoryService fileCategoryService)
: base(service)
{
- this.fileCategoryService = fileCategoryService;
- }
-
- ///
- /// Получение справочника категорий файлов
- ///
- ///
- [HttpGet]
- [Route("/getWellFileCategory")]
- //[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 471225f2..6c243b2c 100644
--- a/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs
+++ b/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
-using AsbCloudInfrastructure.Services;
+using System.ComponentModel.DataAnnotations;
namespace AsbCloudWebApi.Controllers
{
@@ -21,10 +21,29 @@ namespace AsbCloudWebApi.Controllers
{
private readonly IWellFinalDocumentsService wellFinalDocumentsService;
private readonly IWellService wellService;
- public WellFinalDocumentsController(IWellFinalDocumentsService wellFinalDocumentsService, IWellService wellService)
+ private readonly IFileCategoryService fileCategoryService;
+
+ public WellFinalDocumentsController(
+ IWellFinalDocumentsService wellFinalDocumentsService,
+ IWellService wellService,
+ IFileCategoryService fileCategoryService)
{
this.wellFinalDocumentsService = wellFinalDocumentsService;
this.wellService = wellService;
+ 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);
}
///
@@ -33,7 +52,7 @@ namespace AsbCloudWebApi.Controllers
///
///
///
- [HttpGet]
+ [HttpGet("{idWell}")]
[Permission]
[ProducesResponseType(typeof(WellCaseDto), (int)System.Net.HttpStatusCode.OK)]
public async Task GetAsync(int idWell, CancellationToken token = default)
@@ -52,9 +71,8 @@ namespace AsbCloudWebApi.Controllers
///
///
///
- [HttpGet]
+ [HttpGet("{idWell}/availableUsers")]
[Permission]
- [Route("publishers")]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetAvailableUsersAsync(int idWell, CancellationToken token = default)
{
@@ -72,10 +90,10 @@ namespace AsbCloudWebApi.Controllers
///
///
///
- [HttpPut]
+ [HttpPut("{idWell}")]
[Permission("WellFinalDocument.editPublisher")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
- public async Task UpdateRangeAsync(int idWell, IEnumerable dtos, CancellationToken token = default)
+ public async Task UpdateRangeAsync(int idWell, [Required] IEnumerable dtos, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
@@ -91,12 +109,11 @@ namespace AsbCloudWebApi.Controllers
///
///
///
- [HttpGet]
+ [HttpGet("{idWell}/history")]
[Permission]
- [Route("filesHistoryByIdCategory")]
[ProducesResponseType(typeof(WellFinalDocumentsHistoryDto), (int)System.Net.HttpStatusCode.OK)]
public async Task GetFilesHistoryByIdCategory(int idWell,
- int idCategory,
+ [Required] int idCategory,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
@@ -114,10 +131,10 @@ namespace AsbCloudWebApi.Controllers
///
///
///
- [HttpPost]
+ [HttpPost("{idWell}")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
- public async Task SaveCategoryFile(int idWell, int idCategory, IFormFile file, CancellationToken token = default)
+ public async Task SaveCategoryFile(int idWell, [Required] int idCategory, [Required] IFormFile file, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();