Files
parr_api/PARR.API/Controllers/V1/TestController.cs

92 lines
3.1 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
2023-08-01 16:00:33 +10:00
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.API.Services.Interfaces;
using PARR.Constants;
2023-11-30 16:18:14 +10:00
using PARR.DAL.CacheServices;
using PARR.DAL.TransformServices;
2023-08-01 16:00:33 +10:00
namespace PARR.API.Controllers.V1
{
public class TestController : BaseApiController
{
private readonly IClientService clientService;
private readonly IEsppScheduleTransformService esppScheduleTransformService;
2023-11-30 16:18:14 +10:00
private readonly IRedisCacheService redisCacheService;
2023-08-01 16:00:33 +10:00
2023-11-30 16:18:14 +10:00
public TestController(IClientService clientService, IEsppScheduleTransformService esppScheduleTransformService, IRedisCacheService redisCacheService)
2023-08-01 16:00:33 +10:00
{
this.clientService = clientService;
this.esppScheduleTransformService = esppScheduleTransformService;
2023-11-30 16:18:14 +10:00
this.redisCacheService = redisCacheService;
2023-08-01 16:00:33 +10:00
}
/// <summary>
/// Получить мой ip
/// </summary>
/// <returns></returns>
//[Authorize(Roles = ParrRoles.Administrator.Role)]
[Authorize]
2023-08-01 16:00:33 +10:00
[HttpGet(ApiRoutes.Test.GetMyIp)]
public IActionResult GetMyIp()
{
var ipAddress = clientService.GetClientIp();
2023-08-01 16:30:16 +10:00
2023-08-01 16:00:33 +10:00
var ip = ipAddress?.ToString();
return Ok(new Response<object>(new { ip }, true));
}
/// <summary>
/// Получить следующую дату запуска
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="lastRunDate"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.Test.GetNextScheduleDate)]
public async Task<IActionResult> GetNextScheduleDate([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
{
var result = await esppScheduleTransformService.GetNextDateAsync(applicationInWorkId, lastRunDate);
return Ok(result);
}
/// <summary>
/// Получить следующее расписание
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="lastRunDate"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.Test.GetNextSchedule)]
public async Task<IActionResult> GetNextSchedule([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
{
var result = await esppScheduleTransformService.GetNextScheduleAsync(applicationInWorkId, lastRunDate);
return Ok(result);
}
2023-11-30 16:18:14 +10:00
[HttpPost(ApiRoutes.Test.CreateCache)]
public async Task<IActionResult> CreateCache([FromBody] CaheRequestTest request)
{
await redisCacheService.SetCachedDataAsync(request.Key, request, TimeSpan.FromMinutes(1));
var fromCache = await redisCacheService.GetCachedDataAsync<CaheRequestTest>(request.Key);
return Ok(new { fromCache });
}
}
public class CaheRequestTest
{
public required string Key { get; set; }
public required string Value { get; set; }
2023-08-01 16:00:33 +10:00
}
}