feat(api): реализован GetAll UnitFieldValue по Id FieldValue
This commit is contained in:
70
PARR.API/Controllers/V1/UnitFieldController.cs
Normal file
70
PARR.API/Controllers/V1/UnitFieldController.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Справочник полей
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class UnitFieldController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<JobController> logger;
|
||||
private readonly IUnitFieldService unitFieldService;
|
||||
private readonly IMapper mapper;
|
||||
|
||||
public UnitFieldController(
|
||||
ILogger<JobController> logger,
|
||||
IUnitFieldService unitFieldService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.unitFieldService = unitFieldService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Список доступных в БД атрибутов ЭК
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.UnitField.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var unitFields = await unitFieldService.Get().OrderBy(t => t.DisplayName)
|
||||
.ToListAsync();
|
||||
|
||||
if (!unitFields.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<FieldResponse>>(unitFields);
|
||||
|
||||
return Ok(new Response<List<FieldResponse>>(response, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить имя атрибута по Id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.UnitField.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] Guid id)
|
||||
{
|
||||
var unitField = await unitFieldService.Get().FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (unitField == null)
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<FieldResponse>(unitField);
|
||||
|
||||
return Ok(new Response<FieldResponse>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
67
PARR.API/Controllers/V1/UnitFieldValueController.cs
Normal file
67
PARR.API/Controllers/V1/UnitFieldValueController.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Управление значениями атрибутов
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class UnitFieldValueController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<TnkController> logger;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IUnitFieldService unitFieldService;
|
||||
private readonly IUnitFieldValueService unitFieldValueService;
|
||||
|
||||
public UnitFieldValueController(
|
||||
ILogger<TnkController> logger,
|
||||
IMapper mapper,
|
||||
IUnitFieldService unitFieldService,
|
||||
IUnitFieldValueService unitFieldValueService
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.mapper = mapper;
|
||||
this.unitFieldService = unitFieldService;
|
||||
this.unitFieldValueService = unitFieldValueService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Список доступных значений аттрибутов
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.UnitField.GetAllValues)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromRoute] Guid id)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
var query = unitFieldValueService.Get()
|
||||
.Where(t => t.UnitInValues.Any(t => t.FieldId == id))
|
||||
.OrderBy(t => t.Value);
|
||||
|
||||
var fieldValues = await unitFieldValueService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!fieldValues.Any())
|
||||
return NoContent();
|
||||
|
||||
var fielsValuesResponse = mapper.Map<List<UnitFieldValueResponse>>(fieldValues);
|
||||
var paginationResponse = new PagedResponse<UnitFieldValueResponse>(fielsValuesResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user