113 lines
3.6 KiB
C#
113 lines
3.6 KiB
C#
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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Получить мой ip
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(ApiRoutes.Test.GetMyIp)]
|
|
public IActionResult GetMyIp()
|
|
{
|
|
var ipAddress = clientService.GetClientIp();
|
|
|
|
var ip = ipAddress?.ToString();
|
|
|
|
return Ok(new Response<object>(new { ip }, true));
|
|
}
|
|
|
|
|
|
public record GetNextRunRequest(Guid TemplateId, bool IsNew);
|
|
|
|
/// <summary>
|
|
/// Получить nextRun
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost(ApiRoutes.Test.GetNextRun)]
|
|
public async Task<IActionResult> GetNextRun([FromBody] GetNextRunRequest request)
|
|
{
|
|
var nextRun = await nextRunService.GetNextRunForTemplateAsync(request.TemplateId, request.IsNew);
|
|
var template = await templateService.GetAsync(request.TemplateId);
|
|
|
|
return Ok(new Response<object>(new { OldNextRun = template?.NextRun, NewNextRun = nextRun }, true));
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Записать в кэш
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost(ApiRoutes.Test.CreateCache)]
|
|
public async Task<IActionResult> CreateCache()
|
|
{
|
|
//var val = await redisCacheService.GetCachedDataAsync<object>("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<string>(hashKey, "t1");
|
|
|
|
//var getAll = await redisCacheService.GetAllHashFieldsAsync<string>(hashKey);
|
|
|
|
//await redisCacheService.DeleteHashFieldAsync(hashKey, "t1");
|
|
//var getT1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
|
|
|
//var exist = await redisCacheService.HashFieldExistsAsync(hashKey, "t2");
|
|
|
|
//await redisCacheService.DeleteHashAsync(hashKey);
|
|
//var getT_1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
|
|
|
//await redisCacheService.SetHashTtlAsync(hashKey, ttl);
|
|
|
|
return Ok();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|