using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudApp.Requests;
namespace AsbCloudWebApi.Controllers.SAUB
{
///
/// Операции определенные по телеметрии САУБ
///
[Route("api/well/{idWell}/[controller]")]
[ApiController]
public class DetectedOperationController : ControllerBase
{
private readonly IDetectedOperationService detectedOperationService;
private readonly IWellService wellService;
public DetectedOperationController(IDetectedOperationService detectedOperationService, IWellService wellService)
{
this.detectedOperationService = detectedOperationService;
this.wellService = wellService;
}
///
/// получить справочник операций. Отличается от операций заводимых вручную
///
///
///
[HttpGet("categories")]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetCategoriesAsync(CancellationToken token = default)
{
var result = await detectedOperationService.GetCategoriesAsync(token);
return Ok(result);
}
///
/// Получить фильтрованный список операций по телеметрии САУБ
///
///
///
///
///
[HttpGet]
[ProducesResponseType(typeof(DetectedOperationListDto), (int)System.Net.HttpStatusCode.OK)]
public async Task GetAsync(
int idWell,
[FromQuery] DetectedOperationRequest request,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await detectedOperationService.GetAsync(idWell, request, token);
return Ok(result);
}
///
/// Удалить операции.
/// Удаленные операции будут определены повторно сервисом автоматизированного определения операций.
/// Может потребоваться при изменении алгоритмов определения
///
///
///
///
///
[HttpDelete]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task DeleteAsync(
int idWell,
[FromQuery] DetectedOperationRequest request,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await detectedOperationService.DeleteAsync(idWell, request, token);
return Ok(result);
}
}
}