DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/AdminTelemetryController.cs
2024-08-19 10:01:07 +05:00

63 lines
2.1 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers;
/// <summary>
/// Редактор телеметрий для админки
/// </summary>
[Route("api/admin/telemetry")]
[ApiController]
[Authorize]
public class AdminTelemetryController : CrudController<TelemetryDto, ICrudRepository<TelemetryDto>>
{
private readonly ITelemetryService telemetryService;
private readonly ITelemetryDataEditorService telemetryEditorService;
public AdminTelemetryController(ICrudRepository<TelemetryDto> service,
ITelemetryService telemetryService,
ITelemetryDataEditorService telemetryEditorService)
: base(service)
{
this.telemetryService = telemetryService;
this.telemetryEditorService = telemetryEditorService;
}
/// <summary>
/// Merge telemetries. No body required.
/// </summary>
/// <returns></returns>
[HttpPost("/merge/{idFrom}/{idTo}")]
[Permission]
public async Task<IActionResult> MergeTelemetriesAsync(int idFrom, int idTo, CancellationToken token)
{
var count = await telemetryService.MergeAsync(idFrom, idTo, token)
.ConfigureAwait(false);
return Ok(count);
}
/// <summary>
/// Удаление куска телеметрии по запросу
/// </summary>
/// <param name="request">запрос</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete("part")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> DeleteAsync([FromQuery] TelemetryPartDeleteRequest request,CancellationToken token)
{
var result = await telemetryEditorService.DeleteAsync(request, token);
return Ok(result);
}
}