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

47 lines
1.7 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер операций на скважине
/// </summary>
[Route("api/wellOperation")]
[ApiController]
[Authorize]
public class WellOperationController : ControllerBase
{
private readonly IWellOperationService operationService;
private readonly IWellService wellService;
public WellOperationController(IWellOperationService operationService, IWellService wellService)
{
this.operationService = operationService;
this.wellService = wellService;
}
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await operationService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
return Ok(result);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
}
}