65 lines
2.0 KiB
C#
65 lines
2.0 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;
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
{
|
|
/// <summary>
|
|
/// Наряды
|
|
/// </summary>
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
|
public class OrderController : BaseApiController
|
|
{
|
|
private readonly IMapper mapper;
|
|
private readonly IOrderService orderService;
|
|
|
|
public OrderController(
|
|
IMapper mapper,
|
|
IOrderService orderService
|
|
)
|
|
{
|
|
this.mapper = mapper;
|
|
this.orderService = orderService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Получить список нарядов постранично
|
|
/// </summary>
|
|
/// <param name="paginationQuery"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(ApiRoutes.Order.GetAll)]
|
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery)
|
|
{
|
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
|
|
|
var query = orderService.Get()
|
|
.Include(t=>t.Template)
|
|
.Include(s=>s.OrderStatus)
|
|
.Include(s => s.NextStatus)
|
|
.OrderByDescending(t => t.DateCreated);
|
|
|
|
var orders = await orderService.GetPage(query, paginationFilter).ToListAsync();
|
|
|
|
if (!orders.Any())
|
|
return NoContent();
|
|
|
|
var orderResponse = mapper.Map<List<OrderResponse>>(orders);
|
|
var paginationResponse = new PagedResponse<OrderResponse>(orderResponse, true).GetPaginatedProps(paginationFilter, query);
|
|
|
|
return Ok(paginationResponse);
|
|
}
|
|
|
|
}
|
|
}
|