using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using DD.Persistence.Models;
using DD.Persistence.Services.Interfaces;
using System.Net;
namespace DD.Persistence.API.Controllers;
///
/// Работа с параметрами Wits
///
[ApiController]
[Authorize]
[Route("api/[controller]")]
public class WitsDataController : ControllerBase, IWitsDataApi
{
private readonly IWitsDataService witsDataService;
public WitsDataController(IWitsDataService witsDataService)
{
this.witsDataService = witsDataService;
}
///
/// Получить диапазон дат, для которых есть данные в репозитории
///
///
///
///
[HttpGet("{discriminatorId}/datesRange")]
public async Task> GetDatesRangeAsync([FromRoute] Guid discriminatorId, CancellationToken token)
{
var result = await witsDataService.GetDatesRangeAsync(discriminatorId, token);
return result == null ? NoContent() : Ok(result);
}
///
/// Получить порцию записей, начиная с заданной даты
///
///
///
///
///
///
[HttpGet("{discriminatorId}/part")]
public async Task>> GetPart([FromRoute] Guid discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token)
{
var result = await witsDataService.GetPart(discriminatorId, dateBegin, take, token);
return Ok(result);
}
///
/// Получить набор параметров (Wits) для построения графика
///
/// Дискриминатор системы
/// Начало временного интервала
/// Конец временного интервала
/// Количество точек
///
///
[HttpGet("{discriminatorId}/graph")]
public async Task>> GetValuesForGraph([FromRoute] Guid discriminatorId,
[FromQuery] DateTimeOffset dateFrom, [FromQuery] DateTimeOffset dateTo, [FromQuery] int approxPointsCount, CancellationToken token)
{
var result = await witsDataService.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token);
return Ok(result);
}
///
/// Сохранить набор параметров (Wits)
///
///
///
///
[HttpPost]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)]
public async Task AddRange([FromBody] IEnumerable dtos, CancellationToken token)
{
var result = await witsDataService.AddRange(dtos, token);
return CreatedAtAction(nameof(AddRange), result);
}
}