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