82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Persistence.Models;
|
||
using Persistence.Repositories;
|
||
|
||
namespace Persistence.API.Controllers;
|
||
|
||
/// <summary>
|
||
/// Работа с уставками
|
||
/// </summary>
|
||
[ApiController]
|
||
[Authorize]
|
||
[Route("api/[controller]")]
|
||
public class SetpointController : ControllerBase, ISetpointApi
|
||
{
|
||
private readonly ISetpointRepository setpointRepository;
|
||
|
||
public SetpointController(ISetpointRepository setpointRepository)
|
||
{
|
||
this.setpointRepository = setpointRepository;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получить актуальные значения уставок
|
||
/// </summary>
|
||
/// <param name="setpointKeys"></param>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("current")]
|
||
public async Task<ActionResult<IEnumerable<SetpointValueDto>>> GetCurrent([FromQuery] IEnumerable<Guid> setpointKeys, CancellationToken token)
|
||
{
|
||
var result = await setpointRepository.GetCurrent(setpointKeys, token);
|
||
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <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);
|
||
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <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);
|
||
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранить уставку
|
||
/// </summary>
|
||
/// <param name="setpointKey"></param>
|
||
/// <param name="newValue"></param>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<ActionResult<int>> Save(Guid setpointKey, object newValue, CancellationToken token)
|
||
{
|
||
// ToDo: вычитка idUser
|
||
await setpointRepository.Save(setpointKey, newValue, 0, token);
|
||
|
||
return Ok();
|
||
}
|
||
}
|