forked from ddrilling/AsbCloudServer
90 lines
2.8 KiB
C#
90 lines
2.8 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using AsbCloudApp.Data;
|
|||
|
using AsbCloudApp.Exceptions;
|
|||
|
using AsbCloudApp.Repositories;
|
|||
|
using AsbCloudApp.Requests;
|
|||
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace AsbCloudWebApi.Controllers;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Ствол скважины
|
|||
|
/// </summary>
|
|||
|
[Authorize]
|
|||
|
[ApiController]
|
|||
|
[Route("api/well/[controller]")]
|
|||
|
public class WellboreController : ControllerBase
|
|||
|
{
|
|||
|
private readonly IWellOperationRepository wellOperationRepository;
|
|||
|
|
|||
|
public WellboreController(IWellOperationRepository wellOperationRepository)
|
|||
|
{
|
|||
|
this.wellOperationRepository = wellOperationRepository;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Получение ствола скважины
|
|||
|
/// </summary>
|
|||
|
/// <param name="idWell">Id скважины</param>
|
|||
|
/// <param name="idSectionType">Опциональный параметр. Id типа секции</param>
|
|||
|
/// <param name="cancellationToken"></param>
|
|||
|
/// <returns></returns>
|
|||
|
|
|||
|
[HttpGet("{idWell:int}")]
|
|||
|
[ProducesResponseType(typeof(WellboreDto), (int)System.Net.HttpStatusCode.OK)]
|
|||
|
public async Task<IActionResult> GetAsync(int idWell, int? idSectionType, CancellationToken cancellationToken)
|
|||
|
{
|
|||
|
return Ok(await wellOperationRepository.GetWellboreAsync(idWell, idSectionType, cancellationToken));
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Получение списка стволов скважин
|
|||
|
/// </summary>
|
|||
|
/// <param name="ids">Пары идентификаторов скважины и секции</param>
|
|||
|
/// <param name="skip">Опциональный параметр. Количество пропускаемых записей</param>
|
|||
|
/// <param name="take">Опциональный параметр. Количество получаемых записей</param>
|
|||
|
/// <param name="cancellationToken"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ProducesResponseType(typeof(PaginationContainer<WellboreDto>), (int)System.Net.HttpStatusCode.OK)]
|
|||
|
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
|||
|
int? skip,
|
|||
|
int? take,
|
|||
|
CancellationToken cancellationToken)
|
|||
|
{
|
|||
|
var request = new WellboreRequest
|
|||
|
{
|
|||
|
Ids = ParseIds(ids),
|
|||
|
Skip = skip,
|
|||
|
Take = take
|
|||
|
};
|
|||
|
|
|||
|
return Ok(await wellOperationRepository.GetWellboresAsync(request, cancellationToken));
|
|||
|
}
|
|||
|
|
|||
|
private static IEnumerable<(int, int?)> ParseIds(IEnumerable<string> ids)
|
|||
|
{
|
|||
|
var result = new List<(int, int?)>();
|
|||
|
|
|||
|
foreach (var id in ids)
|
|||
|
{
|
|||
|
var idPair = id.Split(',');
|
|||
|
|
|||
|
if (!int.TryParse(idPair[0], out var idWell))
|
|||
|
throw new ArgumentInvalidException("Не удалось получить Id скважины", nameof(ids));
|
|||
|
|
|||
|
if (idPair.Length < 2 || !int.TryParse(idPair[1], out var idWellSectionType))
|
|||
|
{
|
|||
|
result.Add((idWell, null));
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
result.Add((idWell, idWellSectionType));
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|