feat(api): paginationQuery добавлен параметр отключения пагинации. Контроллер ApplicationInWorks GetAll.
This commit is contained in:
@@ -283,6 +283,21 @@ namespace PARR.API.Contracts.V1
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Job
|
||||
/// <summary>
|
||||
/// Альтернативная сущность AppliationInWork
|
||||
/// </summary>
|
||||
public static class Job
|
||||
{
|
||||
public const string GetAll = Base + "/jobs/";
|
||||
//public const string Get = Base + "/jobs/" + getParam;
|
||||
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,5 +53,10 @@
|
||||
_pageSize = pageSizeDefault;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выключить пагинацию
|
||||
/// </summary>
|
||||
public bool IsDisabledPagination { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
||||
31
PARR.API/Contracts/V1/Responses/ApplicationInWorkResponse.cs
Normal file
31
PARR.API/Contracts/V1/Responses/ApplicationInWorkResponse.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class ApplicationInWorkResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public required string TemplateDuration { get; set; }
|
||||
|
||||
public required string ShortDescription { get; set; }
|
||||
|
||||
public required string FullDescription { get; set; }
|
||||
|
||||
public required string Solution { get; set; }
|
||||
|
||||
public DateTimeOffset? LastRun { get; set; }
|
||||
|
||||
public DateTimeOffset NextRun { get; set; }
|
||||
|
||||
public bool IsAgent { get; set; }
|
||||
|
||||
public string? AgentName { get; set; }
|
||||
|
||||
public int? AgentTimeOutSec { get; set; }
|
||||
|
||||
public string? AgentScript { get; set; }
|
||||
|
||||
public WorkResponse? Work { get; set; }
|
||||
|
||||
public ApplicationResponse? Application { get; set; }
|
||||
}
|
||||
}
|
||||
62
PARR.API/Controllers/V1/ApplicationInWorkController.cs
Normal file
62
PARR.API/Controllers/V1/ApplicationInWorkController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// ApplicationInWork
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class ApplicationInWorkController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IApplicationsInWorkService applicationsInWorkService;
|
||||
|
||||
public ApplicationInWorkController(
|
||||
IMapper mapper,
|
||||
IApplicationsInWorkService applicationsInWorkService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.applicationsInWorkService = applicationsInWorkService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список регламентных работ(ApplicationInWork)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Job.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<ApplicationsInWork> query = applicationsInWorkService.Get()
|
||||
.Include(t => t.Application)
|
||||
.Include(t => t.Work)
|
||||
.OrderBy(t => t.ShortDescription);
|
||||
|
||||
var appInWorks = await applicationsInWorkService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!appInWorks.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<ApplicationInWorkResponse>>(appInWorks);
|
||||
var paginationResponse = new PagedResponse<ApplicationInWorkResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,16 @@ namespace PARR.API.Extensions
|
||||
/// <typeparam name="Query"></typeparam>
|
||||
/// <param name="pagedResponse"></param>
|
||||
/// <param name="paginationFilter"></param>
|
||||
/// <param name="quaryAllItemsApplyFilters"></param>
|
||||
/// <param name="queryAllItemsApplyFilters"></param>
|
||||
/// <returns></returns>
|
||||
public static PagedResponse<TypeResponse> GetPaginatedProps<TypeResponse, Query>(
|
||||
this PagedResponse<TypeResponse> pagedResponse,
|
||||
PaginationFilter paginationFilter,
|
||||
IQueryable<Query> quaryAllItemsApplyFilters
|
||||
IQueryable<Query> queryAllItemsApplyFilters
|
||||
)
|
||||
{
|
||||
// TODO: CountAsync - подумать и затолкать в Task
|
||||
int totalItems = quaryAllItemsApplyFilters.Count();//.CountAsync().GetAwaiter().GetResult();
|
||||
int totalItems = queryAllItemsApplyFilters.Count();//.CountAsync().GetAwaiter().GetResult();
|
||||
return CreatePaginatedResponse(totalItems, paginationFilter, pagedResponse);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,17 @@ namespace PARR.API.Extensions
|
||||
private static PagedResponse<T> CreatePaginatedResponse<T>(int totalItems, PaginationFilter paginationFilter, PagedResponse<T> pagedResponse)
|
||||
{
|
||||
pagedResponse.TotalItems = totalItems;
|
||||
pagedResponse.PageNumber = paginationFilter.PageNumber >= 1 ? paginationFilter.PageNumber : (int?)null;
|
||||
pagedResponse.PageSize = paginationFilter.PageSize >= 1 ? paginationFilter.PageSize : (int?)null;
|
||||
//pagedResponse.PageNumber = paginationFilter.PageNumber >= 1 ? paginationFilter.PageNumber : (int?)null;
|
||||
//pagedResponse.PageSize = paginationFilter.PageSize >= 1 ? paginationFilter.PageSize : (int?)null;
|
||||
|
||||
pagedResponse.PageNumber = paginationFilter.IsDisabledPagination
|
||||
? 1
|
||||
: (paginationFilter.PageNumber >= 1 ? paginationFilter.PageNumber : (int?)null);
|
||||
|
||||
pagedResponse.PageSize = paginationFilter.IsDisabledPagination
|
||||
? totalItems
|
||||
: (paginationFilter.PageSize >= 1 ? paginationFilter.PageSize : (int?)null);
|
||||
|
||||
pagedResponse.TotalPage =
|
||||
(pagedResponse.TotalItems.HasValue && pagedResponse.PageSize.HasValue)
|
||||
? (int)Math.Ceiling(pagedResponse.TotalItems.Value / (double)pagedResponse.PageSize.Value)
|
||||
|
||||
@@ -173,10 +173,9 @@ namespace PARR.API.MappingProfiles
|
||||
CreateMap<AgentHistoryLevel, AgentHistoryLevelResponse>();
|
||||
|
||||
CreateMap<AgentHistory, AgentHistoryResponse>()
|
||||
.ForMember(t => t.Date, o => o.MapFrom(s => s.DateCreated))
|
||||
.ForMember(t => t.Level, o => o.MapFrom(s => s.AgentHistoryLevel))
|
||||
.ForMember(t => t.TemplateName, o => o.MapFrom(s => s.Template!.Name));
|
||||
|
||||
.ForMember(d => d.Date, o => o.MapFrom(s => s.DateCreated))
|
||||
.ForMember(d => d.Level, o => o.MapFrom(s => s.AgentHistoryLevel))
|
||||
.ForMember(d => d.TemplateName, o => o.MapFrom(s => s.Template!.Name));
|
||||
|
||||
|
||||
#region User
|
||||
@@ -208,6 +207,10 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
CreateMap<ApplicationsInWork, ApplicationInWorkResponse>()
|
||||
.ForMember(d => d.Work, o => o.MapFrom(s => s.Work))
|
||||
.ForMember(d => d.Application, o => o.MapFrom(s => s.Application));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user