2021-08-24 10:59:10 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2021-08-02 14:45:13 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-08-24 10:59:10 +05:00
|
|
|
|
using System.Collections.Generic;
|
2021-08-10 14:36:35 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-08-02 14:45:13 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2021-08-12 11:52:23 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер секций скважины
|
|
|
|
|
/// </summary>
|
2021-08-10 14:36:35 +05:00
|
|
|
|
[Route("api/well/{idWell}/sections")]
|
2021-08-02 14:45:13 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
2021-08-10 14:36:35 +05:00
|
|
|
|
public class WellSectionController : ControllerBase
|
2021-08-02 14:45:13 +05:00
|
|
|
|
{
|
2021-08-10 17:43:13 +05:00
|
|
|
|
private readonly IWellSectionService sectionsService;
|
|
|
|
|
private readonly IWellService wellService;
|
2021-08-02 14:45:13 +05:00
|
|
|
|
|
2021-08-10 17:43:13 +05:00
|
|
|
|
public WellSectionController(IWellSectionService sectionsService, IWellService wellService)
|
2021-08-10 14:36:35 +05:00
|
|
|
|
{
|
2021-08-10 17:43:13 +05:00
|
|
|
|
this.sectionsService = sectionsService;
|
|
|
|
|
this.wellService = wellService;
|
2021-08-02 14:45:13 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 12:33:05 +05:00
|
|
|
|
[HttpGet]
|
2021-08-20 16:56:21 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetSectionsByWellIdAsync(int idWell,
|
2021-08-11 16:54:42 +05:00
|
|
|
|
CancellationToken token = default)
|
2021-08-10 14:36:35 +05:00
|
|
|
|
{
|
2021-08-24 10:59:10 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
2021-08-10 17:43:13 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-20 16:56:21 +05:00
|
|
|
|
var result = await sectionsService.GetSectionsByWellIdAsync(idWell, token)
|
2021-08-20 13:56:01 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2021-08-10 14:36:35 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
2021-08-10 17:43:13 +05:00
|
|
|
|
{
|
2021-08-18 14:52:52 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
2021-08-10 17:43:13 +05:00
|
|
|
|
}
|
2021-08-02 14:45:13 +05:00
|
|
|
|
}
|
|
|
|
|
}
|