2024-11-20 15:22:23 +05:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-11-14 15:17:43 +05:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Persistence.Models;
|
|
|
|
using Persistence.Repositories;
|
|
|
|
|
|
|
|
namespace Persistence.API.Controllers;
|
|
|
|
[ApiController]
|
2024-11-20 15:22:23 +05:00
|
|
|
[Authorize]
|
2024-11-14 15:17:43 +05:00
|
|
|
[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> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
|
|
|
|
{
|
|
|
|
var result = await this.timeSeriesDataRepository.GetAsync(dateBegin, dateEnd, token);
|
|
|
|
return Ok(result);
|
2024-11-19 11:32:56 +05:00
|
|
|
|
2024-11-14 15:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("datesRange")]
|
2024-11-18 14:22:09 +05:00
|
|
|
public async Task<IActionResult> GetDatesRangeAsync(CancellationToken token)
|
2024-11-14 15:17:43 +05:00
|
|
|
{
|
2024-11-20 15:22:23 +05:00
|
|
|
var result = await this.timeSeriesDataRepository.GetDatesRangeAsync(token);
|
|
|
|
return Ok(result);
|
2024-11-14 15:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<IActionResult> InsertRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
|
|
|
|
{
|
|
|
|
var result = await this.timeSeriesDataRepository.InsertRange(dtos, token);
|
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
}
|