diff --git a/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
index 364595f4..27b76c62 100644
--- a/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
+++ b/PARR.API/Contracts/V1/Requests/Queries/HostQuery.cs
@@ -3,7 +3,7 @@
public class HostQuery
{
///
- /// Поиск по маске ЭК. Например: "*-ДВС"
+ /// Поиск по маске ЭК. Например: "ВРТ-*-ДВС"
///
public string? Mask { get; set; }
}
diff --git a/PARR.API/Contracts/V1/Responses/AttributeResponse.cs b/PARR.API/Contracts/V1/Responses/AttributeResponse.cs
new file mode 100644
index 00000000..b269df07
--- /dev/null
+++ b/PARR.API/Contracts/V1/Responses/AttributeResponse.cs
@@ -0,0 +1,17 @@
+namespace PARR.API.Contracts.V1.Responses
+{
+ public class AttributeResponse
+ {
+ public Guid Id { get; set; }
+
+ ///
+ /// Имя из поля DisplayName, если пустое - берём AihitName
+ ///
+ public required string Name { get; set; }
+
+ ///
+ /// Соответствующее полю значение
+ ///
+ public required string Value { get; set; }
+ }
+}
diff --git a/PARR.API/Contracts/V1/Responses/UnitResponse.cs b/PARR.API/Contracts/V1/Responses/UnitResponse.cs
new file mode 100644
index 00000000..5f68a4ab
--- /dev/null
+++ b/PARR.API/Contracts/V1/Responses/UnitResponse.cs
@@ -0,0 +1,18 @@
+namespace PARR.API.Contracts.V1.Responses
+{
+ public class UnitResponse
+ {
+ public Guid Id { get; set; }
+
+ public required string Name { get; set; }
+ }
+
+
+ ///
+ /// Response с всеми аттребутами и их значениями
+ ///
+ public class UnitWithAttributesResponse : UnitResponse
+ {
+ public List? Attributes { get; set; }
+ }
+}
diff --git a/PARR.API/Controllers/V1/HostController.cs b/PARR.API/Controllers/V1/HostController.cs
index 736f2d40..60e7eb3e 100644
--- a/PARR.API/Controllers/V1/HostController.cs
+++ b/PARR.API/Controllers/V1/HostController.cs
@@ -11,7 +11,9 @@ using PARR.API.Extensions;
using PARR.BLL.Helpers;
using PARR.Constants;
using PARR.DAL.DomainModels;
+using PARR.DAL.Models.Unit;
using PARR.DAL.Services.Interfaces;
+using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.API.Controllers.V1
{
@@ -20,11 +22,17 @@ namespace PARR.API.Controllers.V1
{
private readonly IMapper mapper;
private readonly IHostService hostService;
+ private readonly IUnitService unitService;
- public HostController(IMapper mapper, IHostService hostService)
+ public HostController(
+ IMapper mapper,
+ IHostService hostService,
+ IUnitService unitService
+ )
{
this.mapper = mapper;
this.hostService = hostService;
+ this.unitService = unitService;
}
@@ -38,23 +46,42 @@ namespace PARR.API.Controllers.V1
{
var paginationFilter = mapper.Map(paginationQuery);
- IQueryable query = hostService.Get()
- .Include(t=>t.WorkGroup).ThenInclude(t=>t!.ResponseArea)
- .Include(s => s.EkStatus)
- .Include(s => s.ResponseArea)
- .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
- .OrderBy(t => t.Ek);
+ //IQueryable query = hostService.Get()
+ // .Include(t=>t.WorkGroup).ThenInclude(t=>t!.ResponseArea)
+ // .Include(s => s.EkStatus)
+ // .Include(s => s.ResponseArea)
+ // .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
+ // .OrderBy(t => t.Ek);
+
+ //if (!string.IsNullOrEmpty(request.Mask))
+ // query = query.Where(t => EF.Functions.Like(t.Ek.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
+
+ //var hosts = await hostService.GetPage(query, paginationFilter).ToListAsync();
+
+ //if (!hosts.Any())
+ // return NoContent();
+
+ //var hostResponse = mapper.Map>(hosts);
+ //var paginationResponse = new PagedResponse(hostResponse, true).GetPaginatedProps(paginationFilter, query);
+
+ IQueryable query = unitService.Get()
+ .AsNoTracking()
+ .Include(t => t.UnitValues)
+ .ThenInclude(uv => uv.Value)
+ .Include(tf => tf.UnitValues)
+ .ThenInclude(uv => uv.Field)
+ .OrderBy(t => t.Name);
if (!string.IsNullOrEmpty(request.Mask))
- query = query.Where(t => EF.Functions.Like(t.Ek.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
+ query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
- var hosts = await hostService.GetPage(query, paginationFilter).ToListAsync();
+ var units = await unitService.GetPage(query, paginationFilter).ToListAsync();
- if (!hosts.Any())
+ if (!units.Any())
return NoContent();
- var hostResponse = mapper.Map>(hosts);
- var paginationResponse = new PagedResponse(hostResponse, true).GetPaginatedProps(paginationFilter, query);
+ var unitResponse = mapper.Map>(units);
+ var paginationResponse = new PagedResponse(unitResponse, true).GetPaginatedProps(paginationFilter, query);
return Ok(paginationResponse);
}
@@ -68,19 +95,31 @@ namespace PARR.API.Controllers.V1
[HttpGet(ApiRoutes.Host.Get)]
public async Task GetById([FromRoute] Guid id)
{
- var host = await hostService.Get()
- .Include(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
- .Include(s => s.EkStatus)
- .Include(s => s.ResponseArea)
- .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
- .FirstOrDefaultAsync(t => t.Id == id);
+ //var host = await hostService.Get()
+ // .Include(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
+ // .Include(s => s.EkStatus)
+ // .Include(s => s.ResponseArea)
+ // .Include(t => t.ApplicationsInHosts).ThenInclude(t => t.Application).ThenInclude(t => t!.ApplicationType)
+ // .FirstOrDefaultAsync(t => t.Id == id);
- if (host == null)
+ //if (host == null)
+ // return NotFound();
+
+ //var response = mapper.Map(host);
+
+ var unit = await unitService.Get()
+ .AsNoTracking()
+ .Include(t => t.UnitValues)
+ .ThenInclude(uv => uv.Value)
+ .Include(tf => tf.UnitValues)
+ .ThenInclude(uv => uv.Field)
+ .FirstOrDefaultAsync(t => t.Id == id);
+ if (unit == null)
return NotFound();
- var response = mapper.Map(host);
+ var response = mapper.Map(unit);
- return Ok(new Response(response, true));
+ return Ok(new Response(response, true));
}
diff --git a/PARR.API/MappingProfiles/DomainToResponseProfile.cs b/PARR.API/MappingProfiles/DomainToResponseProfile.cs
index c57fd9f0..a18c93a2 100644
--- a/PARR.API/MappingProfiles/DomainToResponseProfile.cs
+++ b/PARR.API/MappingProfiles/DomainToResponseProfile.cs
@@ -7,6 +7,7 @@ using PARR.Constants.Shortcodes;
using PARR.DAL.DomainModels;
using PARR.DAL.Extensions;
using PARR.DAL.Models;
+using PARR.DAL.Models.Unit;
namespace PARR.API.MappingProfiles
{
@@ -103,6 +104,21 @@ namespace PARR.API.MappingProfiles
#endregion
+ #region Unit
+
+ CreateMap()
+ .ForMember(d => d.Id, o => o.MapFrom(s => s.Value!.Id))
+ .ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.Field!.DisplayName)) ? s.Field!.AihitName : s.Field!.DisplayName))
+ .ForMember(d => d.Value, o => o.MapFrom(s => s.Value!.Value));
+
+ CreateMap()
+ .Include()
+ .ForMember(d => d.Name, o => o.MapFrom(s => s.Name));
+
+ CreateMap()
+ .ForMember(d => d.Attributes, o => o.MapFrom(s => s.UnitValues!.OrderBy(s => (string.IsNullOrEmpty(s.Field!.DisplayName)) ? s.Field!.AihitName : s.Field!.DisplayName)));
+ #endregion
+
#region WorkGroup
CreateMap();