2024-12-12 16:56:25 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-12-04 14:13:25 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Models;
|
|
|
|
|
using DD.Persistence.Services.Interfaces;
|
2024-12-12 16:56:25 +05:00
|
|
|
|
using System.Net;
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.API.Controllers;
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-06 11:40:18 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Работа с параметрами Wits
|
|
|
|
|
/// </summary>
|
2024-12-04 14:13:25 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class WitsDataController : ControllerBase, IWitsDataApi
|
|
|
|
|
{
|
2024-12-12 16:56:25 +05:00
|
|
|
|
private readonly IWitsDataService witsDataService;
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
public WitsDataController(IWitsDataService witsDataService)
|
|
|
|
|
{
|
|
|
|
|
this.witsDataService = witsDataService;
|
|
|
|
|
}
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить диапазон дат, для которых есть данные в репозитории
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="discriminatorId"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{discriminatorId}/datesRange")]
|
|
|
|
|
public async Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync([FromRoute] Guid discriminatorId, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await witsDataService.GetDatesRangeAsync(discriminatorId, token);
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
return result == null ? NoContent() : Ok(result);
|
|
|
|
|
}
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить порцию записей, начиная с заданной даты
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="discriminatorId"></param>
|
|
|
|
|
/// <param name="dateBegin"></param>
|
|
|
|
|
/// <param name="take"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{discriminatorId}/part")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetPart([FromRoute] Guid discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await witsDataService.GetPart(discriminatorId, dateBegin, take, token);
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить набор параметров (Wits) для построения графика
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="discriminatorId">Дискриминатор системы</param>
|
|
|
|
|
/// <param name="dateFrom">Начало временного интервала</param>
|
|
|
|
|
/// <param name="dateTo">Конец временного интервала</param>
|
|
|
|
|
/// <param name="approxPointsCount">Количество точек</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{discriminatorId}/graph")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<WitsDataDto>>> GetValuesForGraph([FromRoute] Guid discriminatorId,
|
|
|
|
|
[FromQuery] DateTimeOffset dateFrom, [FromQuery] DateTimeOffset dateTo, [FromQuery] int approxPointsCount, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await witsDataService.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token);
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-12-04 14:13:25 +05:00
|
|
|
|
|
2024-12-12 16:56:25 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранить набор параметров (Wits)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)]
|
|
|
|
|
public async Task<IActionResult> AddRange([FromBody] IEnumerable<WitsDataDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await witsDataService.AddRange(dtos, token);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(AddRange), result);
|
|
|
|
|
}
|
2024-12-04 14:13:25 +05:00
|
|
|
|
}
|