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 { /// /// Контроллер секций скважины /// [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")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task 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 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 CanUserAccessToWellAsync(int idWell, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false); } } }