2024-12-02 15:14:00 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-11-25 10:09:38 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Models;
|
|
|
|
|
using DD.Persistence.Repositories;
|
2024-12-09 13:19:55 +05:00
|
|
|
|
using System.Net;
|
2025-01-17 13:54:26 +05:00
|
|
|
|
using System.Text.Json;
|
2025-01-13 17:45:49 +05:00
|
|
|
|
using DD.Persistence.Models.Common;
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.API.Controllers;
|
2024-11-27 13:08:06 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Работа с уставками
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class SetpointController : ControllerBase, ISetpointApi
|
2024-11-18 09:39:24 +05:00
|
|
|
|
{
|
2024-12-09 13:19:55 +05:00
|
|
|
|
private readonly ISetpointRepository setpointRepository;
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
public SetpointController(ISetpointRepository setpointRepository)
|
|
|
|
|
{
|
|
|
|
|
this.setpointRepository = setpointRepository;
|
|
|
|
|
}
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить актуальные значения уставок
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="setpointKeys"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("current")]
|
2025-01-17 16:39:36 +05:00
|
|
|
|
public async Task<ActionResult<Dictionary<Guid, object>>> GetCurrent([FromQuery] IEnumerable<Guid> setpointKeys, CancellationToken token)
|
2024-12-09 13:19:55 +05:00
|
|
|
|
{
|
2025-01-17 16:39:36 +05:00
|
|
|
|
var result = await setpointRepository.GetCurrentDictionary(setpointKeys, token);
|
2024-11-18 15:05:12 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить значения уставок за определенный момент времени
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="setpointKeys"></param>
|
|
|
|
|
/// <param name="historyMoment"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("history")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<SetpointValueDto>>> GetHistory([FromQuery] IEnumerable<Guid> setpointKeys, [FromQuery] DateTimeOffset historyMoment, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await setpointRepository.GetHistory(setpointKeys, historyMoment, token);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить историю изменений значений уставок
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="setpointKeys"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("log")]
|
|
|
|
|
public async Task<ActionResult<Dictionary<Guid, IEnumerable<SetpointLogDto>>>> GetLog([FromQuery] IEnumerable<Guid> setpointKeys, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await setpointRepository.GetLog(setpointKeys, token);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить диапазон дат, для которых есть данные в репозитории
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("range")]
|
|
|
|
|
public async Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await setpointRepository.GetDatesRangeAsync(token);
|
2024-12-02 15:14:00 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-12-02 15:14:00 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить порцию записей, начиная с заданной даты
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dateBegin"></param>
|
|
|
|
|
/// <param name="take"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("part")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<SetpointLogDto>>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await setpointRepository.GetPart(dateBegin, take, token);
|
2024-12-02 15:14:00 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-12-02 15:14:00 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранить уставку
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="setpointKey"></param>
|
|
|
|
|
/// <param name="newValue"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)]
|
|
|
|
|
public async Task<IActionResult> Add(Guid setpointKey, object newValue, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var userId = User.GetUserId<Guid>();
|
2025-01-17 13:54:26 +05:00
|
|
|
|
await setpointRepository.Add(setpointKey, (JsonElement)newValue, userId, token);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-12-09 13:19:55 +05:00
|
|
|
|
return CreatedAtAction(nameof(Add), true);
|
|
|
|
|
}
|
2024-11-18 09:39:24 +05:00
|
|
|
|
}
|