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

80 lines
2.9 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер секций скважины
/// </summary>
[ApiController]
[Authorize]
[Route("api")]
public class WellOperationStatController : ControllerBase
{
private readonly IWellOperationsStatService operationsStatService;
private readonly IWellService wellService;
public WellOperationStatController(IWellOperationsStatService sectionsService, IWellService wellService)
{
this.operationsStatService = sectionsService;
this.wellService = wellService;
}
[HttpGet]
2021-08-25 11:30:50 +05:00
[Route("cluster/{idCluster}/stat")]
[ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatClusterAsync(int idCluster,
CancellationToken token = default)
{
2021-08-25 11:30:50 +05:00
// TODO: Fix next commented lines
//if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false))
// return Forbid();
var result = await operationsStatService.GetStatClusterAsync(idCluster, token)
.ConfigureAwait(false);
return Ok(result);
}
[HttpGet]
2021-08-25 11:30:50 +05:00
[Route("well/{idWell}/stat")]
[ProducesResponseType(typeof(StatWellDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatWellAsync(int idWell,
CancellationToken token = default)
{
2021-08-25 11:30:50 +05:00
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await operationsStatService.GetStatWellAsync(idWell, token)
.ConfigureAwait(false);
return Ok(result);
}
2021-08-25 11:30:50 +05:00
[HttpGet]
[Route("well/{idWell}/tvd")]
[ProducesResponseType(typeof(IEnumerable<PlanFactPredictBase<WellOperationDto>>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetTvdAsync(int idWell,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await operationsStatService.GetTvdAsync(idWell, token)
.ConfigureAwait(false);
return Ok(result);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
}
}