2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2021-04-07 18:01:56 +05:00
|
|
|
|
[Route("api/well")]
|
2021-04-02 17:28:07 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public WellController(IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-18 12:38:49 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список доступных скважин
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Список скважин</returns>
|
2021-04-02 17:28:07 +05:00
|
|
|
|
[HttpGet]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-04-02 17:28:07 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> GetWellsAsync(CancellationToken token = default)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (idCompany is null)
|
2021-05-18 11:11:16 +05:00
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-08-24 10:59:10 +05:00
|
|
|
|
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
token).ConfigureAwait(false);
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
return Ok(wells);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-20 16:18:07 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает информацию о требуемой скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> Id требуемой скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Информация о требуемой скважине </returns>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
[HttpGet("{idWell}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-20 16:18:07 +05:00
|
|
|
|
[ProducesResponseType(typeof(WellDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
2022-06-09 11:19:52 +05:00
|
|
|
|
return Forbid();
|
2021-10-20 16:18:07 +05:00
|
|
|
|
|
2022-06-16 12:33:05 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultAsync(idWell,
|
2021-10-20 16:18:07 +05:00
|
|
|
|
token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(well);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-18 12:38:49 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактирует указанные поля скважины
|
|
|
|
|
/// </summary>
|
2021-10-18 16:30:14 +05:00
|
|
|
|
/// <param name="dto"> Объект параметров скважины.
|
|
|
|
|
/// IdWellType: 1 - Наклонно-направленная, 2 - Горизонтальная.
|
|
|
|
|
/// State: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
2021-10-18 12:38:49 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2022-06-09 11:19:52 +05:00
|
|
|
|
[HttpPut]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-18 12:38:49 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2022-06-09 11:19:52 +05:00
|
|
|
|
public async Task<IActionResult> UpdateWellAsync(WellDto dto,
|
2021-10-18 16:30:14 +05:00
|
|
|
|
CancellationToken token = default)
|
2021-10-18 12:38:49 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
2022-06-09 11:19:52 +05:00
|
|
|
|
dto.Id, token).ConfigureAwait(false))
|
2021-10-18 12:38:49 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-06-09 11:19:52 +05:00
|
|
|
|
var result = await wellService.UpdateAsync(dto, token)
|
2021-10-18 16:30:14 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2021-10-18 12:38:49 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|