68 lines
2.5 KiB
C#
68 lines
2.5 KiB
C#
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);
|
|
}
|
|
|
|
}
|
|
}
|