2021-10-12 12:17:46 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/well/{idWell}/composite")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellCompositeController : ControllerBase
|
|
|
|
|
{
|
2021-10-14 12:30:51 +05:00
|
|
|
|
private readonly IWellCompositeService wellCompositeService;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
2021-10-14 12:30:51 +05:00
|
|
|
|
public WellCompositeController(IWellCompositeService wellCompositeService, IWellService wellService)
|
2021-10-12 12:17:46 +05:00
|
|
|
|
{
|
2021-10-14 12:30:51 +05:00
|
|
|
|
this.wellCompositeService = wellCompositeService;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает композитную скважину для скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины для которой собрана композитная скважина</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-12 12:17:46 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellCompositeDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-10-14 12:30:51 +05:00
|
|
|
|
var result = await wellCompositeService.GetAsync(idWell, token).ConfigureAwait(false);
|
2021-10-12 12:17:46 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает или заменяет композитную скважину для скважины с idWell
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины для которой собрана композитная скважина</param>
|
|
|
|
|
/// <param name="wellComposites">Секции композитной скважины</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-12 12:17:46 +05:00
|
|
|
|
public async Task<IActionResult> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-10-14 12:30:51 +05:00
|
|
|
|
var result = await wellCompositeService.SaveAsync(idWell, wellComposites, token).ConfigureAwait(false);
|
2021-10-12 12:17:46 +05:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|