feat(api): список нарядов постранично
This commit is contained in:
@@ -211,6 +211,17 @@ namespace PARR.API.Contracts.V1
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Наряды
|
||||
|
||||
public static class Order
|
||||
{
|
||||
public const string GetAll = Base + "/orders/";
|
||||
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,5 +15,22 @@
|
||||
|
||||
public class OrderResponse : OrderResponseBase
|
||||
{
|
||||
public DateTimeOffset DateCreated { get; set; }
|
||||
|
||||
public string? WorkGroup { get; set; }
|
||||
|
||||
public Guid? TemplateId { get; set; }
|
||||
|
||||
public string TemplateName { get; set; } = string.Empty;
|
||||
|
||||
public OrderStatusResponse? Status { get; set; }
|
||||
|
||||
public OrderStatusResponse? NextStatus { get; set; }
|
||||
|
||||
public string ShortName { get; set; } = string.Empty;
|
||||
|
||||
public DateTimeOffset? GenerateDate { get; set; }
|
||||
|
||||
public DateTimeOffset ExpirationDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
64
PARR.API/Controllers/V1/OrderController.cs
Normal file
64
PARR.API/Controllers/V1/OrderController.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace PARR.API.MappingProfiles
|
||||
.ForMember(d => d.Initiator, o => o.MapFrom<TemplateInitiatorResolver>())
|
||||
.ForMember(d => d.ClosingCode, o => o.MapFrom<TemplateClosingCodeResolver>())
|
||||
.ForMember(d => d.Category, o => o.MapFrom<TemplateCategoryResolver>())
|
||||
.ForMember(d => d.SyncStatus, o => o.MapFrom(s => s.RobotConfigurations.OrderBy(t=>t.RobotCode)))
|
||||
.ForMember(d => d.SyncStatus, o => o.MapFrom(s => s.RobotConfigurations.OrderBy(t => t.RobotCode)))
|
||||
.ForMember(d => d.Schedule, o => o.MapFrom<TemplateScheduleResolver>())
|
||||
.ForMember(d => d.Agent, o => o.MapFrom(s => s.ApplicationsInWork))
|
||||
.ForMember(d => d.NextRun, o => o.MapFrom(s => s.ApplicationsInWork!.NextRun))
|
||||
@@ -202,7 +202,9 @@ namespace PARR.API.MappingProfiles
|
||||
.ForMember(s => s.Status, o => o.MapFrom(s => s.OrderStatus))
|
||||
.ForMember(s => s.NextStatus, o => o.MapFrom(s => s.NextStatus));
|
||||
|
||||
CreateMap<Order, OrderResponse>();
|
||||
CreateMap<Order, OrderResponse>()
|
||||
.ForMember(s => s.Status, o => o.MapFrom(s => s.OrderStatus))
|
||||
.ForMember(s => s.NextStatus, o => o.MapFrom(s => s.NextStatus));
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user