diff --git a/PARR.API/Contracts/V1/Requests/Queries/OrderQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/OrderQuery.cs
new file mode 100644
index 00000000..21852dbe
--- /dev/null
+++ b/PARR.API/Contracts/V1/Requests/Queries/OrderQuery.cs
@@ -0,0 +1,10 @@
+namespace PARR.API.Contracts.V1.Requests.Queries
+{
+ public class OrderQuery
+ {
+ ///
+ /// Поиск по ИД шаблона
+ ///
+ public Guid? TemplateId { get; set; }
+ }
+}
diff --git a/PARR.API/Contracts/V1/Responses/TemplateResponse.cs b/PARR.API/Contracts/V1/Responses/TemplateResponse.cs
index e9299d8e..32c185e2 100644
--- a/PARR.API/Contracts/V1/Responses/TemplateResponse.cs
+++ b/PARR.API/Contracts/V1/Responses/TemplateResponse.cs
@@ -35,5 +35,7 @@
/// Расписание
///
public EsppScheduleResponse? Schedule { get; set; }
+
+ public int OrderCount { get; set; }
}
}
diff --git a/PARR.API/Controllers/V1/OrderController.cs b/PARR.API/Controllers/V1/OrderController.cs
index e281ba28..f71368dd 100644
--- a/PARR.API/Controllers/V1/OrderController.cs
+++ b/PARR.API/Controllers/V1/OrderController.cs
@@ -10,6 +10,7 @@ using PARR.API.Controllers.V1.Base;
using PARR.API.Extensions;
using PARR.Constants;
using PARR.DAL.DomainModels;
+using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
@@ -39,16 +40,19 @@ namespace PARR.API.Controllers.V1
///
///
[HttpGet(ApiRoutes.Order.GetAll)]
- public async Task GetAll([FromQuery] PaginationQuery paginationQuery)
+ public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] OrderQuery filter)
{
var paginationFilter = mapper.Map(paginationQuery);
- var query = orderService.Get()
+ IQueryable query = orderService.Get()
.Include(t => t.Template)
.Include(s => s.OrderStatus)
.Include(s => s.NextStatus)
.OrderByDescending(t => t.DateCreated);
+ if (filter.TemplateId.HasValue)
+ query = query.Where(t => t.TemplateId == filter.TemplateId.Value);
+
var orders = await orderService.GetPage(query, paginationFilter).ToListAsync();
if (!orders.Any())
diff --git a/PARR.API/Controllers/V1/TemplateController.cs b/PARR.API/Controllers/V1/TemplateController.cs
index 03cf6bc1..0c3cf8fb 100644
--- a/PARR.API/Controllers/V1/TemplateController.cs
+++ b/PARR.API/Controllers/V1/TemplateController.cs
@@ -57,6 +57,7 @@ namespace PARR.API.Controllers.V1
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
+ .Include(t => t.Orders)
.OrderBy(t => t.Name)
.AsSplitQuery();
@@ -90,6 +91,7 @@ namespace PARR.API.Controllers.V1
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
+ .Include(t=>t.Orders)
.AsSplitQuery()
.FirstOrDefaultAsync(t => t.Id == id);
@@ -114,6 +116,7 @@ namespace PARR.API.Controllers.V1
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
+ .Include(t => t.Orders)
.AsSplitQuery()
.FirstOrDefaultAsync(t => t.Id == id);
@@ -143,6 +146,7 @@ namespace PARR.API.Controllers.V1
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
+ .Include(t => t.Orders)
.AsSplitQuery()
.FirstOrDefaultAsync(t => t.Id == id);
diff --git a/PARR.API/MappingProfiles/DomainToResponseProfile.cs b/PARR.API/MappingProfiles/DomainToResponseProfile.cs
index 832812a9..b540fd00 100644
--- a/PARR.API/MappingProfiles/DomainToResponseProfile.cs
+++ b/PARR.API/MappingProfiles/DomainToResponseProfile.cs
@@ -34,7 +34,8 @@ namespace PARR.API.MappingProfiles
.ForMember(d => d.Schedule, o => o.MapFrom())
.ForMember(d => d.Agent, o => o.MapFrom(s => s.ApplicationsInWork))
.ForMember(d => d.NextRun, o => o.MapFrom(s => s.ApplicationsInWork!.NextRun))
- .ForMember(d => d.LastRun, o => o.MapFrom(s => s.ApplicationsInWork!.LastRun));
+ .ForMember(d => d.LastRun, o => o.MapFrom(s => s.ApplicationsInWork!.LastRun))
+ .ForMember(d => d.OrderCount, o => o.MapFrom(s => s.Orders.Count()));
// === Template ===