feat(api): HostController.Response Field, Value выделены в отдельные поля
This commit is contained in:
11
PARR.API/Contracts/V1/Requests/BaseRequests/FullQuery.cs
Normal file
11
PARR.API/Contracts/V1/Requests/BaseRequests/FullQuery.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace PARR.API.Contracts.V1.Requests.BaseRequests
|
||||
{
|
||||
public class FullQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Полный запрос, включающий все данные
|
||||
/// </summary>
|
||||
public bool IsFull { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
||||
|
||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||
{
|
||||
public class HostQuery
|
||||
public class HostQuery: FullQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Поиск по маске ЭК. Например: "ВРТ-*-ДВС"
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
{
|
||||
public class AttributeResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Имя из поля DisplayName, если пустое - берём AihitName
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
public required FieldResponse Field { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Соответствующее полю значение
|
||||
/// </summary>
|
||||
public required string Value { get; set; }
|
||||
public required ValueResponse Value { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
15
PARR.API/Contracts/V1/Responses/FieldBaseResponse.cs
Normal file
15
PARR.API/Contracts/V1/Responses/FieldBaseResponse.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class FieldBaseResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class FieldResponse : FieldBaseResponse
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class UnitResponse
|
||||
public class UnitBaseResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
@@ -8,11 +8,29 @@
|
||||
}
|
||||
|
||||
|
||||
public class UnitResponse : UnitBaseResponse
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Response с всеми аттребутами и их значениями
|
||||
/// </summary>
|
||||
public class UnitWithAttributesResponse : UnitResponse
|
||||
public class UnitWithAttributesResponse : UnitBaseResponse
|
||||
{
|
||||
public List<AttributeResponse>? Attributes { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
14
PARR.API/Contracts/V1/Responses/ValueBaseResponse.cs
Normal file
14
PARR.API/Contracts/V1/Responses/ValueBaseResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class ValueBaseResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ValueResponse : ValueBaseResponse
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -65,16 +65,18 @@ namespace PARR.API.Controllers.V1
|
||||
//var paginationResponse = new PagedResponse<HostWithApplicationsResponse>(hostResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
IQueryable<Unit> 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.Name.ToLower(), SqlHelpers.RegexToLike(request.Mask)));
|
||||
|
||||
if (request.IsFull)
|
||||
query = query
|
||||
.Include(t => t.UnitValues)
|
||||
.ThenInclude(uv => uv.Value)
|
||||
.Include(tf => tf.UnitValues)
|
||||
.ThenInclude(uv => uv.Field);
|
||||
|
||||
var units = await unitService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!units.Any())
|
||||
@@ -108,12 +110,12 @@ namespace PARR.API.Controllers.V1
|
||||
//var response = mapper.Map<HostWithApplicationsResponse>(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();
|
||||
|
||||
|
||||
@@ -106,12 +106,16 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
#region Unit
|
||||
|
||||
CreateMap<UnitInValue, AttributeResponse>()
|
||||
.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<UnitField, FieldResponse>()
|
||||
.ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.DisplayName)) ? s.AihitName : s.DisplayName));
|
||||
|
||||
CreateMap<Unit, UnitResponse>()
|
||||
CreateMap<UnitFieldValue, ValueResponse>();
|
||||
|
||||
CreateMap<UnitInValue, AttributeResponse>()
|
||||
.ForMember(d => d.Field, o => o.MapFrom(s => s.Field))
|
||||
.ForMember(d => d.Value, o => o.MapFrom(s => s.Value));
|
||||
|
||||
CreateMap<Unit, UnitBaseResponse>()
|
||||
.Include<Unit, UnitWithAttributesResponse>()
|
||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.Name));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user