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.DAL.Cache.Services.Base; using PARR.DAL.NextRunServices; using PARR.DAL.Services.Interfaces; namespace PARR.API.Controllers.V1 { [Authorize] public class TestController : BaseApiController { private readonly IClientService clientService; private readonly IRedisCacheService redisCacheService; private readonly INextRunService nextRunService; private readonly ITemplateService templateService; public TestController( IClientService clientService, IRedisCacheService redisCacheService, INextRunService nextRunService, ITemplateService templateService ) { this.clientService = clientService; this.redisCacheService = redisCacheService; this.nextRunService = nextRunService; this.templateService = templateService; } /// /// Получить мой ip /// /// [HttpGet(ApiRoutes.Test.GetMyIp)] public IActionResult GetMyIp() { var ipAddress = clientService.GetClientIp(); var ip = ipAddress?.ToString(); return Ok(new Response(new { ip }, true)); } public record GetNextRunRequest(Guid TemplateId, bool IsNew); /// /// Получить nextRun /// /// [HttpPost(ApiRoutes.Test.GetNextRun)] public async Task GetNextRun([FromBody] GetNextRunRequest request) { var nextRun = await nextRunService.GetNextRunForTemplateAsync(request.TemplateId, request.IsNew); var template = await templateService.GetAsync(request.TemplateId); return Ok(new Response(new { OldNextRun = template?.NextRun, NewNextRun = nextRun }, true)); } /// /// Записать в кэш /// /// /// [HttpPost(ApiRoutes.Test.CreateCache)] public async Task CreateCache() { //var val = await redisCacheService.GetCachedDataAsync("96dAoIH/8Q9Bg8VY"); //var hashKey = redisCacheService.GetKey(new[] { "test", "mxa" }); //var ttl = TimeSpan.FromMinutes(10); //await redisCacheService.SetHashFieldAsync(hashKey, "t1", "val1", ttl); //await redisCacheService.SetHashFieldAsync(hashKey, "t2", "val2"); //await redisCacheService.SetHashFieldAsync(hashKey, "t3", "val3"); //var length = await redisCacheService.GetHashLengthAsync(hashKey); //var get = await redisCacheService.GetHashFieldAsync(hashKey, "t1"); //var getAll = await redisCacheService.GetAllHashFieldsAsync(hashKey); //await redisCacheService.DeleteHashFieldAsync(hashKey, "t1"); //var getT1 = await redisCacheService.GetHashFieldAsync(hashKey, "t1"); //var exist = await redisCacheService.HashFieldExistsAsync(hashKey, "t2"); //await redisCacheService.DeleteHashAsync(hashKey); //var getT_1 = await redisCacheService.GetHashFieldAsync(hashKey, "t1"); //await redisCacheService.SetHashTtlAsync(hashKey, ttl); return Ok(); } } }