79 lines
2.9 KiB
C#
79 lines
2.9 KiB
C#
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using PARR.API.Contracts.V1.Requests.Queries;
|
|||
|
|
using PARR.API.Contracts.V1;
|
|||
|
|
using PARR.API.Controllers.V1.Base;
|
|||
|
|
using AutoMapper;
|
|||
|
|
using PARR.DAL.DomainModels;
|
|||
|
|
using PARR.DAL.Models;
|
|||
|
|
using PARR.DAL.Services.Interfaces;
|
|||
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using PARR.API.Contracts.V1.Responses;
|
|||
|
|
using PARR.API.Contracts.V1.Responses.Base;
|
|||
|
|
using PARR.API.Extensions;
|
|||
|
|
using System.Runtime.CompilerServices;
|
|||
|
|
using PARR.API.Services.Interfaces;
|
|||
|
|
|
|||
|
|
namespace PARR.API.Controllers.V1
|
|||
|
|
{
|
|||
|
|
public class ShchedullerController : BaseApiController
|
|||
|
|
{
|
|||
|
|
private readonly IMapper mapper;
|
|||
|
|
private readonly ISchedulerService schedulerService;
|
|||
|
|
private readonly IClientService clientService;
|
|||
|
|
|
|||
|
|
public ShchedullerController(
|
|||
|
|
IMapper mapper,
|
|||
|
|
ISchedulerService schedulerService,
|
|||
|
|
IClientService clientService
|
|||
|
|
)
|
|||
|
|
{
|
|||
|
|
this.mapper = mapper;
|
|||
|
|
this.schedulerService = schedulerService;
|
|||
|
|
this.clientService = clientService;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Список всех планировщиков постранично в соотвествии с фильтрами
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="paginationQuery"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[HttpGet(ApiRoutes.Scheduler.GetAll)]
|
|||
|
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] SchedulerGetAllQuery filter)
|
|||
|
|
{
|
|||
|
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
|||
|
|
IQueryable<Scheduler> query = schedulerService.Get().OrderBy(s => s.StartAt);
|
|||
|
|
|
|||
|
|
if (filter.IsEnabled.HasValue)
|
|||
|
|
query = query.Where(t => t.IsEnabled == filter.IsEnabled);
|
|||
|
|
|
|||
|
|
if (filter.StartDatePlanned.HasValue)
|
|||
|
|
query = query.Where(t => t.StartAt.DateTime.Date <= filter.StartDatePlanned.Value.DateTime.Date); ;
|
|||
|
|
|
|||
|
|
var schedulers = await schedulerService.GetPage(query, paginationFilter).ToListAsync();
|
|||
|
|
|
|||
|
|
if (!schedulers.Any())
|
|||
|
|
return NoContent();
|
|||
|
|
|
|||
|
|
var schedulerResponse = mapper.Map<List<SchedulerGetAllResponse>>(schedulers);
|
|||
|
|
var paginationResponse = new PagedResponse<SchedulerGetAllResponse>(schedulerResponse, true).GetPaginatedProps(paginationFilter, query);
|
|||
|
|
|
|||
|
|
return Ok(paginationResponse);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpGet(ApiRoutes.Scheduler.GetByIp)]
|
|||
|
|
public async Task<IActionResult> GetByClientIP([FromQuery] SchedulerGetByIpQuery requestQuery)
|
|||
|
|
{
|
|||
|
|
var ip = requestQuery.Ip ?? clientService.GetClientIp()?.ToString();
|
|||
|
|
if (string.IsNullOrEmpty(ip))
|
|||
|
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Client IP address is null." } }));
|
|||
|
|
|
|||
|
|
// TODO;
|
|||
|
|
|
|||
|
|
return Ok();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|