DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/LimitingParameterController.cs
2022-11-23 11:19:52 +05:00

48 lines
1.7 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;
}
[HttpGet("stat")]
[ProducesResponseType(typeof(IEnumerable<LimitingParameterDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetInfosAsync([FromQuery] LimitingParameterRequest request, CancellationToken token = default)
{
if (!await UserHasAccesToWellAsync(request.IdWell, token))
return Forbid();
var subsystemResult = await limitingParameterService.GetStatOrDefaultAsync(request, token);
return Ok(subsystemResult);
}
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;
}
}
}