persistence/Persistence.API/Controllers/TimeSeriesController.cs
Olga Nemt 1fdd199954 1. Убран Id у DataSaub, теперь в качестве первичного ключа выступает Date
2. Автотесты для методов GetDatesRande, GetResampledData.
3. Рефакторинг
2024-11-22 15:47:00 +05:00

51 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Persistence.Models;
using Persistence.Repositories;
namespace Persistence.API.Controllers;
[ApiController]
[Authorize]
[Route("api/[controller]")]
public class TimeSeriesController<TDto> : ControllerBase, ITimeSeriesDataApi<TDto>
where TDto : class, ITimeSeriesAbstractDto, new()
{
private ITimeSeriesDataRepository<TDto> timeSeriesDataRepository;
public TimeSeriesController(ITimeSeriesDataRepository<TDto> timeSeriesDataRepository)
{
this.timeSeriesDataRepository = timeSeriesDataRepository;
}
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get(DateTimeOffset dateBegin, CancellationToken token)
{
var result = await this.timeSeriesDataRepository.GetGtDate(dateBegin, token);
return Ok(result);
}
[HttpGet("datesRange")]
public async Task<IActionResult> GetDatesRange(CancellationToken token)
{
var result = await this.timeSeriesDataRepository.GetDatesRange(token);
return Ok(result);
}
[HttpGet("resampled")]
public async Task<IActionResult> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024)
{
var result = await this.timeSeriesDataRepository.GetResampledData(dateBegin, intervalSec, approxPointsCount);
return Ok(result);
}
[HttpPost]
public async Task<IActionResult> InsertRange(IEnumerable<TDto> dtos, CancellationToken token)
{
var result = await this.timeSeriesDataRepository.InsertRange(dtos, token);
return Ok(result);
}
}