persistence/Persistence.API/Controllers/WitsDataController.cs

82 lines
2.7 KiB
C#
Raw Normal View History

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;
}
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории
/// </summary>
/// <param name="discriminatorId"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("datesRange")]
public async Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync([FromQuery] int discriminatorId, CancellationToken token)
{
var result = await witsDataService.GetDatesRangeAsync(discriminatorId, token);
return Ok(result);
}
/// <summary>
/// Получить порцию записей, начиная с заданной даты
/// </summary>
/// <param name="discriminatorId"></param>
/// <param name="dateBegin"></param>
/// <param name="take"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("part")]
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetPart([FromQuery] int discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token)
{
var result = await witsDataService.GetPart(discriminatorId, dateBegin, take, token);
return Ok(result);
}
/// <summary>
/// Получить набор параметров (Wits) для построения графика
/// </summary>
/// <param name="dateFrom"></param>
/// <param name="dateTo"></param>
/// <param name="limit"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("graph")]
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetValuesForGraph([FromQuery] DateTimeOffset dateFrom, [FromQuery] DateTimeOffset dateTo, [FromQuery] int limit, CancellationToken token)
{
var result = await witsDataService.GetValuesForGraph(dateFrom, dateTo);
return Ok(result);
}
/// <summary>
/// Сохранить набор параметров (Wits)
/// </summary>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)]
public async Task<IActionResult> InsertRange([FromBody] IEnumerable<WitsDataDto> dtos, CancellationToken token)
{
var result = await witsDataService.InsertRange(dtos, token);
return CreatedAtAction(nameof(InsertRange), result);
}
}