using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; 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; using PARR.DAL.CacheServices; using PARR.DAL.TransformServices; namespace PARR.API.Controllers.V1 { public class TestController : BaseApiController { private readonly IClientService clientService; private readonly IEsppScheduleTransformService esppScheduleTransformService; private readonly IRedisCacheService redisCacheService; public TestController(IClientService clientService, IEsppScheduleTransformService esppScheduleTransformService, IRedisCacheService redisCacheService) { this.clientService = clientService; this.esppScheduleTransformService = esppScheduleTransformService; this.redisCacheService = redisCacheService; } /// /// Получить мой ip /// /// //[Authorize(Roles = ParrRoles.Administrator.Role)] [Authorize] [HttpGet(ApiRoutes.Test.GetMyIp)] public IActionResult GetMyIp() { var ipAddress = clientService.GetClientIp(); var ip = ipAddress?.ToString(); return Ok(new Response(new { ip }, true)); } /// /// Получить следующую дату запуска /// /// /// /// [HttpGet(ApiRoutes.Test.GetNextScheduleDate)] public async Task GetNextScheduleDate([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate) { var result = await esppScheduleTransformService.GetNextDateAsync(applicationInWorkId, lastRunDate); return Ok(result); } /// /// Получить следующее расписание /// /// /// /// [HttpGet(ApiRoutes.Test.GetNextSchedule)] public async Task GetNextSchedule([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate) { var result = await esppScheduleTransformService.GetNextScheduleAsync(applicationInWorkId, lastRunDate); return Ok(result); } [HttpPost(ApiRoutes.Test.CreateCache)] public async Task CreateCache([FromBody] CaheRequestTest request) { await redisCacheService.SetCachedDataAsync(request.Key, request, TimeSpan.FromMinutes(1)); var fromCache = await redisCacheService.GetCachedDataAsync(request.Key); return Ok(new { fromCache }); } } public class CaheRequestTest { public required string Key { get; set; } public required string Value { get; set; } } }