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

66 lines
2.3 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 sectionsService;
private readonly IWellService wellService;
public WellOperationStatController(IWellOperationsStatService sectionsService, IWellService wellService)
{
this.sectionsService = 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();
2021-08-25 11:30:50 +05:00
var result = await sectionsService.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();
2021-08-25 11:30:50 +05:00
var result = await sectionsService.GetStatWellAsync(idWell, token)
.ConfigureAwait(false);
return Ok(result);
}
2021-08-25 11:30:50 +05:00
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);
}
}
}