using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using DD.Persistence.Models; using DD.Persistence.Repositories; using System.Net; namespace DD.Persistence.API.Controllers; /// /// Работа с уставками /// [ApiController] [Authorize] [Route("api/[controller]")] public class SetpointController : ControllerBase, ISetpointApi { private readonly ISetpointRepository setpointRepository; public SetpointController(ISetpointRepository setpointRepository) { this.setpointRepository = setpointRepository; } /// /// Получить актуальные значения уставок /// /// /// /// [HttpGet("current")] public async Task>> GetCurrent([FromQuery] IEnumerable setpointKeys, CancellationToken token) { var result = await setpointRepository.GetCurrent(setpointKeys, token); return Ok(result); } /// /// Получить значения уставок за определенный момент времени /// /// /// /// /// [HttpGet("history")] public async Task>> GetHistory([FromQuery] IEnumerable setpointKeys, [FromQuery] DateTimeOffset historyMoment, CancellationToken token) { var result = await setpointRepository.GetHistory(setpointKeys, historyMoment, token); return Ok(result); } /// /// Получить историю изменений значений уставок /// /// /// /// [HttpGet("log")] public async Task>>> GetLog([FromQuery] IEnumerable setpointKeys, CancellationToken token) { var result = await setpointRepository.GetLog(setpointKeys, token); return Ok(result); } /// /// Получить диапазон дат, для которых есть данные в репозитории /// /// /// [HttpGet("range")] public async Task> GetDatesRangeAsync(CancellationToken token) { var result = await setpointRepository.GetDatesRangeAsync(token); return Ok(result); } /// /// Получить порцию записей, начиная с заданной даты /// /// /// /// /// [HttpGet("part")] public async Task>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token) { var result = await setpointRepository.GetPart(dateBegin, take, token); return Ok(result); } /// /// Сохранить уставку /// /// /// /// /// [HttpPost] [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] public async Task Add(Guid setpointKey, object newValue, CancellationToken token) { var userId = User.GetUserId(); await setpointRepository.Add(setpointKey, newValue, userId, token); return CreatedAtAction(nameof(Add), true); } }