2024-11-18 09:39:24 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Persistence.Models;
|
|
|
|
|
using Persistence.Repositories;
|
|
|
|
|
|
|
|
|
|
namespace Persistence.API.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class SetpointController : ControllerBase, ISetpointApi
|
|
|
|
|
{
|
|
|
|
|
private readonly ISetpointRepository setpointRepository;
|
|
|
|
|
|
|
|
|
|
public SetpointController(ISetpointRepository setpointRepository)
|
|
|
|
|
{
|
|
|
|
|
this.setpointRepository = setpointRepository;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
[HttpGet("current")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<SetpointValueDto>>> GetCurrent([FromQuery] IEnumerable<Guid> setpointKeys, CancellationToken token)
|
2024-11-18 09:39:24 +05:00
|
|
|
|
{
|
2024-11-18 15:05:12 +05:00
|
|
|
|
var result = await setpointRepository.GetCurrent(setpointKeys, token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
[HttpGet("history")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<SetpointValueDto>>> GetHistory([FromQuery] IEnumerable<Guid> setpointKeys, [FromQuery] DateTimeOffset historyMoment, CancellationToken token)
|
2024-11-18 09:39:24 +05:00
|
|
|
|
{
|
2024-11-18 15:05:12 +05:00
|
|
|
|
var result = await setpointRepository.GetHistory(setpointKeys, historyMoment, token);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
[HttpGet("log")]
|
|
|
|
|
public async Task<ActionResult<Dictionary<Guid, IEnumerable<SetpointLogDto>>>> GetLog([FromQuery] IEnumerable<Guid> setpointKeys, CancellationToken token)
|
2024-11-18 09:39:24 +05:00
|
|
|
|
{
|
2024-11-18 15:05:12 +05:00
|
|
|
|
var result = await setpointRepository.GetLog(setpointKeys, token);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
[HttpPost]
|
2024-11-18 15:05:12 +05:00
|
|
|
|
public async Task<ActionResult<int>> Save(Guid setpointKey, object newValue, CancellationToken token)
|
2024-11-18 09:39:24 +05:00
|
|
|
|
{
|
2024-11-20 15:29:58 +05:00
|
|
|
|
// ToDo: вычитка idUser
|
|
|
|
|
await setpointRepository.Save(setpointKey, newValue, 0, token);
|
2024-11-18 09:39:24 +05:00
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
return Ok();
|
2024-11-18 09:39:24 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|