DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs

90 lines
3.7 KiB
C#
Raw Normal View History

2022-04-28 15:04:13 +05:00
using AsbCloudApp.Data;
2022-06-15 14:57:37 +05:00
using AsbCloudApp.Requests;
2022-04-28 15:04:13 +05:00
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
2022-06-15 14:57:37 +05:00
using System.Threading.Tasks;
2022-04-28 15:04:13 +05:00
namespace AsbCloudWebApi.Controllers.SAUB
{
/// <summary>
/// Операции определенные по телеметрии САУБ
/// </summary>
[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;
}
/// <summary>
/// получить справочник операций. Отличается от операций заводимых вручную
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("categories")]
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetCategoriesAsync(CancellationToken token = default)
{
var result = await detectedOperationService.GetCategoriesAsync(token);
return Ok(result);
}
/// <summary>
/// Получить фильтрованный список операций по телеметрии САУБ
/// </summary>
/// <param name="idWell"></param>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(DetectedOperationListDto), (int)System.Net.HttpStatusCode.OK)]
2022-04-28 15:04:13 +05:00
public async Task<IActionResult> 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);
}
/// <summary>
/// Удалить операции.
/// Удаленные операции будут определены повторно сервисом автоматизированного определения операций.
/// Может потребоваться при изменении алгоритмов определения
/// </summary>
/// <param name="idWell"></param>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> 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);
}
}
}