DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/AdminTelemetryController.cs

72 lines
2.5 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Requests;
2021-09-10 11:28:57 +05:00
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
2021-12-17 12:48:58 +05:00
using System.Threading;
using System.Threading.Tasks;
2021-09-10 11:28:57 +05:00
namespace AsbCloudWebApi.Controllers
{
2022-06-16 17:37:10 +05:00
/// <summary>
/// Редактор телеметрий для админки
/// </summary>
2021-09-10 11:28:57 +05:00
[Route("api/admin/telemetry")]
[ApiController]
[Authorize]
public class AdminTelemetryController : CrudController<TelemetryDto, ICrudRepository<TelemetryDto>>
2021-09-10 11:28:57 +05:00
{
2021-09-29 10:12:54 +05:00
private readonly ITelemetryService telemetryService;
private readonly ITelemetryDataEditorService telemetryEditorService;
2021-09-29 10:12:54 +05:00
public AdminTelemetryController(ICrudRepository<TelemetryDto> service,
ITelemetryService telemetryService,
ITelemetryDataEditorService telemetryEditorService)
2021-09-10 11:28:57 +05:00
: base(service)
{
2021-09-29 10:12:54 +05:00
this.telemetryService = telemetryService;
this.telemetryEditorService = telemetryEditorService;
2021-09-29 10:12:54 +05:00
}
/// <summary>
2021-12-17 13:04:33 +05:00
/// Merge telemetries. No body required.
2021-09-29 10:12:54 +05:00
/// </summary>
/// <returns></returns>
[HttpPost("/merge/{idFrom}/{idTo}")]
[Permission]
public async Task<IActionResult> MergeTelemetriesAsync(int idFrom, int idTo, CancellationToken token)
2021-09-29 10:12:54 +05:00
{
2021-12-17 12:48:58 +05:00
var count = await telemetryService.MergeAsync(idFrom, idTo, token)
.ConfigureAwait(false);
2021-09-29 10:12:54 +05:00
return Ok(count);
2021-09-10 11:28:57 +05:00
}
/// <summary>
/// Удаление куска телеметрии
/// </summary>
/// <param name="telemetryId">ключ телеметрии</param>
/// <param name="gDate">начало интервала удаления</param>
/// <param name="lDate">конец интервала удаления</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete("/part/{telemetryId}")]
[Permission]
public async Task<IActionResult> DeleteAsync(int telemetryId,
DateTimeOffset? gDate,
DateTimeOffset? lDate,
CancellationToken token)
{
var request = new TelemetryPartDeleteRequest()
{
IdTelemetry = telemetryId,
GeDate = gDate,
LeDate = lDate
};
if(gDate.HasValue || lDate.HasValue)
await telemetryEditorService.DeleteAsync(request, token);
return Ok();
}
2021-09-10 11:28:57 +05:00
}
}