77 lines
2.7 KiB
C#
77 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using DD.Persistence.Models;
|
||
using DD.Persistence.Repositories;
|
||
|
||
namespace DD.Persistence.API.Controllers;
|
||
|
||
[ApiController]
|
||
[Authorize]
|
||
[Route("api/[controller]")]
|
||
public class TimeSeriesController<TDto> : ControllerBase, ITimeSeriesDataApi<TDto>
|
||
where TDto : class, ITimeSeriesAbstractDto, new()
|
||
{
|
||
private readonly ITimeSeriesDataRepository<TDto> timeSeriesDataRepository;
|
||
|
||
public TimeSeriesController(ITimeSeriesDataRepository<TDto> timeSeriesDataRepository)
|
||
{
|
||
this.timeSeriesDataRepository = timeSeriesDataRepository;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получить список объектов, удовлетворяющий диапазону дат
|
||
/// </summary>
|
||
/// <param name="dateBegin"></param>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
public async Task<IActionResult> Get(DateTimeOffset dateBegin, CancellationToken token)
|
||
{
|
||
var result = await timeSeriesDataRepository.GetGtDate(dateBegin, token);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получить диапазон дат, для которых есть данные в репозитории
|
||
/// </summary>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("datesRange")]
|
||
public async Task<IActionResult> GetDatesRange(CancellationToken token)
|
||
{
|
||
var result = await timeSeriesDataRepository.GetDatesRange(token);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получить список объектов с прореживанием, удовлетворяющий диапазону дат
|
||
/// </summary>
|
||
/// <param name="dateBegin"></param>
|
||
/// <param name="intervalSec"></param>
|
||
/// <param name="approxPointsCount"></param>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("resampled")]
|
||
public async Task<IActionResult> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
|
||
{
|
||
var result = await timeSeriesDataRepository.GetResampledData(dateBegin, intervalSec, approxPointsCount, token);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Добавить записи
|
||
/// </summary>
|
||
/// <param name="dtos"></param>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<IActionResult> AddRange(IEnumerable<TDto> dtos, CancellationToken token)
|
||
{
|
||
var result = await timeSeriesDataRepository.AddRange(dtos, token);
|
||
return Ok(result);
|
||
}
|
||
|
||
|
||
}
|