forked from ddrilling/AsbCloudServer
fda5385e46
- Add #nullable, - Add WellRequest, - Remove obsolete method
117 lines
4.3 KiB
C#
117 lines
4.3 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// Инфо о скважине
|
||
/// </summary>
|
||
[Route("api/well")]
|
||
[ApiController]
|
||
[Authorize]
|
||
public class WellController : ControllerBase
|
||
{
|
||
private readonly IWellService wellService;
|
||
|
||
public WellController(IWellService wellService)
|
||
{
|
||
this.wellService = wellService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Возвращает список доступных скважин
|
||
/// </summary>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns>Список скважин</returns>
|
||
[HttpGet]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> GetWellsAsync(CancellationToken token = default)
|
||
{
|
||
var idCompany = User.GetCompanyId();
|
||
|
||
if (idCompany is null)
|
||
return NoContent();
|
||
|
||
var wells = await wellService.GetAsync(new() { IdCompany = idCompany },
|
||
token).ConfigureAwait(false);
|
||
|
||
return Ok(wells);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Возвращает список доступных скважин
|
||
/// </summary>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns>Список скважин</returns>
|
||
[HttpGet("wellTree")]
|
||
[ProducesResponseType(typeof(IEnumerable<DepositBranchDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> GetWellTreeAsync(CancellationToken token = default)
|
||
{
|
||
var idCompany = User.GetCompanyId();
|
||
|
||
if (idCompany is null)
|
||
return NoContent();
|
||
|
||
var wells = await wellService.GetWellTreeAsync((int)idCompany,
|
||
token).ConfigureAwait(false);
|
||
|
||
return Ok(wells);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Возвращает информацию о требуемой скважине
|
||
/// </summary>
|
||
/// <param name="idWell"> Id требуемой скважины </param>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns>Информация о требуемой скважине </returns>
|
||
[HttpGet("{idWell}")]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(WellDto), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
||
{
|
||
var idCompany = User.GetCompanyId();
|
||
|
||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
||
return Forbid();
|
||
|
||
var well = await wellService.GetOrDefaultAsync(idWell,
|
||
token).ConfigureAwait(false);
|
||
|
||
return Ok(well);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Редактирует указанные поля скважины
|
||
/// </summary>
|
||
/// <param name="dto"> Объект параметров скважины.
|
||
/// IdWellType: 1 - Наклонно-направленная, 2 - Горизонтальная.
|
||
/// State: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns></returns>
|
||
[HttpPut]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> UpdateWellAsync(WellDto dto,
|
||
CancellationToken token = default)
|
||
{
|
||
var idCompany = User.GetCompanyId();
|
||
|
||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||
dto.Id, token).ConfigureAwait(false))
|
||
return Forbid();
|
||
|
||
var result = await wellService.UpdateAsync(dto, token)
|
||
.ConfigureAwait(false);
|
||
|
||
return Ok(result);
|
||
|
||
}
|
||
}
|
||
}
|