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

65 lines
2.3 KiB
C#
Raw Permalink Normal View History

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;
2024-08-19 10:01:07 +05:00
namespace AsbCloudWebApi.Controllers;
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class LimitingParameterController : ControllerBase
{
2024-08-19 10:01:07 +05:00
private readonly ILimitingParameterService limitingParameterService;
private readonly IWellService wellService;
2024-08-19 10:01:07 +05:00
public LimitingParameterController(ILimitingParameterService limitingParameterService,
IWellService wellService)
{
this.limitingParameterService = limitingParameterService;
this.wellService = wellService;
}
2024-08-19 10:01:07 +05:00
/// <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);
}
2024-08-19 10:01:07 +05:00
/// <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);
}
2024-08-19 10:01:07 +05:00
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;
}
}