using AsbCloudApp.Data; using AsbCloudApp.Requests; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; using System.Threading; namespace AsbCloudWebApi.Controllers; [Route("api/[controller]")] [ApiController] [Authorize] public class LimitingParameterController : ControllerBase { private readonly ILimitingParameterService limitingParameterService; private readonly IWellService wellService; public LimitingParameterController(ILimitingParameterService limitingParameterService, IWellService wellService) { this.limitingParameterService = limitingParameterService; this.wellService = wellService; } /// /// Получение статистики по ограничивающим параметрам /// /// /// /// [HttpGet("stat")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetStatAsync([FromQuery] LimitingParameterRequest request, CancellationToken token) { if (!await UserHasAccesToWellAsync(request.IdWell, token)) return Forbid(); var subsystemResult = await limitingParameterService.GetStatAsync(request, token); return Ok(subsystemResult); } /// /// Получение словаря названий ограничений /// /// [HttpGet("names")] [ProducesResponseType(typeof(Dictionary), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetLimitingParameteraNames() { var feedRegulatorData = limitingParameterService.GetLimitingParameteraNames(); return Ok(feedRegulatorData); } protected async Task UserHasAccesToWellAsync(int idWell, CancellationToken token) { var idCompany = User.GetCompanyId(); if (idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token) .ConfigureAwait(false)) return true; return false; } }