2021-08-24 16:47:10 +05:00
|
|
|
|
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 sectionsService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public WellOperationStatController(IWellOperationsStatService sectionsService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.sectionsService = sectionsService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("well/{idWell}/stat")]
|
2021-08-25 11:13:56 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<StatOperationsDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-24 16:47:10 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationStatByWellAsync(int idWell,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await sectionsService.GetOperationStatByWellAsync(idWell, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("cluster/{idCluster}/stat")]
|
|
|
|
|
[ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetOperationStatByClusterAsync(int idCluster,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Fix next commented lines
|
|
|
|
|
//if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false))
|
|
|
|
|
// return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await sectionsService.GetOperationStatByClusterAsync(idCluster, 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|