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

66 lines
2.5 KiB
C#

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;
}
/// <summary>
/// Получение статистики по ограничивающим параметрам
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("stat")]
[ProducesResponseType(typeof(IEnumerable<LimitingParameterDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatAsync([FromQuery] LimitingParameterRequest request, CancellationToken token)
{
if (!await UserHasAccesToWellAsync(request.IdWell, token))
return Forbid();
var subsystemResult = await limitingParameterService.GetStatAsync(request, token);
return Ok(subsystemResult);
}
/// <summary>
/// Получение словаря названий ограничений
/// </summary>
/// <returns></returns>
[HttpGet("names")]
[ProducesResponseType(typeof(Dictionary<int, string>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetLimitingParameteraNames()
{
var feedRegulatorData = limitingParameterService.GetLimitingParameteraNames();
return Ok(feedRegulatorData);
}
protected async Task<bool> 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;
}
}
}