feat(api): в work getAll добавлен фильр по имени. ApplicationController GetAll + filter
This commit is contained in:
@@ -209,7 +209,6 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Наряды
|
#region Наряды
|
||||||
|
|
||||||
public static class Order
|
public static class Order
|
||||||
@@ -222,7 +221,6 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region TNK
|
#region TNK
|
||||||
|
|
||||||
public static class Process
|
public static class Process
|
||||||
@@ -298,6 +296,10 @@
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public static class Application
|
||||||
|
{
|
||||||
|
public const string GetAll = Base + "/applications/";
|
||||||
|
}
|
||||||
|
|
||||||
public static class EkStatus
|
public static class EkStatus
|
||||||
{
|
{
|
||||||
|
|||||||
18
PARR.API/Contracts/V1/Requests/Queries/ApplicationQuery.cs
Normal file
18
PARR.API/Contracts/V1/Requests/Queries/ApplicationQuery.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using PARR.DAL.Contracts;
|
||||||
|
|
||||||
|
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||||
|
{
|
||||||
|
public class ApplicationQuery
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск по имени. Например: "tomcat"
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск по типу: 0 - APP, 1 - OS, 2 - DB
|
||||||
|
/// </summary>
|
||||||
|
public ApplicationTypesEnum? Type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,5 +6,10 @@
|
|||||||
/// С иерархией до процесса
|
/// С иерархией до процесса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AllParents { get; set; } = false;
|
public bool AllParents { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск по имени. Например: "прочее"
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
74
PARR.API/Controllers/V1/ApplicationController.cs
Normal file
74
PARR.API/Controllers/V1/ApplicationController.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Cors.Infrastructure;
|
||||||
|
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.Models;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Управление приложениями
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class ApplicationController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly ILogger<ApplicationController> logger;
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
private readonly IApplicationService applicationService;
|
||||||
|
|
||||||
|
public ApplicationController(
|
||||||
|
ILogger<ApplicationController> logger,
|
||||||
|
IMapper mapper,
|
||||||
|
IApplicationService applicationService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.mapper = mapper;
|
||||||
|
this.applicationService = applicationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Список приложений постранично
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paginationQuery"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.Application.GetAll)]
|
||||||
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] ApplicationQuery filter)
|
||||||
|
{
|
||||||
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
|
IQueryable<Application> query = applicationService.Get()
|
||||||
|
.Include(t => t.ApplicationType)
|
||||||
|
.OrderBy(t => t.Name);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(filter.Name))
|
||||||
|
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
||||||
|
|
||||||
|
if (filter.Type.HasValue)
|
||||||
|
query = query.Where(t => t.ApplicationType!.Name == filter.Type.Value.ToString());
|
||||||
|
|
||||||
|
|
||||||
|
var apps = await applicationService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
|
if (!apps.Any())
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
var appsResponse = mapper.Map<List<ApplicationResponse>>(apps);
|
||||||
|
var paginationResponse = new PagedResponse<ApplicationResponse>(appsResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||||
|
|
||||||
|
return Ok(paginationResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,22 +52,26 @@ namespace PARR.API.Controllers.V1
|
|||||||
/// <param name="paginationQuery"></param>
|
/// <param name="paginationQuery"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(ApiRoutes.Work.GetAll)]
|
[HttpGet(ApiRoutes.Work.GetAll)]
|
||||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] WorkGetAllQuery requestQuery)
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] WorkGetAllQuery filter)
|
||||||
{
|
{
|
||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
IQueryable<Work> query = workService.Get()
|
IQueryable<Work> query = workService.Get()
|
||||||
.OrderBy(t => t.Name);
|
.OrderBy(t => t.Name);
|
||||||
|
|
||||||
if (requestQuery.AllParents)
|
if (filter.AllParents)
|
||||||
query = query.Include(t => t.Tnk).ThenInclude(s => s.Subprocess).ThenInclude(p => p.Process);
|
query = query.Include(t => t.Tnk).ThenInclude(s => s.Subprocess).ThenInclude(p => p.Process);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(filter.Name))
|
||||||
|
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
||||||
|
|
||||||
|
|
||||||
var works = await workService.GetPage(query, paginationFilter).ToListAsync();
|
var works = await workService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!works.Any())
|
if (!works.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
if (requestQuery.AllParents)
|
if (filter.AllParents)
|
||||||
{
|
{
|
||||||
//todo: тут бесконечность в маппинге
|
//todo: тут бесконечность в маппинге
|
||||||
// респонс с иерархией вверх до процесса
|
// респонс с иерархией вверх до процесса
|
||||||
|
|||||||
Reference in New Issue
Block a user