2023-08-14 18:30:31 +05:00
|
|
|
|
using System.Collections.Generic;
|
2023-08-15 16:08:51 +05:00
|
|
|
|
using System.Linq;
|
2023-08-14 18:30:31 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Exceptions;
|
|
|
|
|
using AsbCloudApp.Requests;
|
2023-08-15 14:20:28 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-08-14 18:30:31 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-08-15 12:28:39 +05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2023-08-14 18:30:31 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ствол скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
2023-08-15 17:43:49 +05:00
|
|
|
|
[Route("api/[controller]")]
|
2023-08-14 18:30:31 +05:00
|
|
|
|
public class WellboreController : ControllerBase
|
|
|
|
|
{
|
2023-08-15 14:20:28 +05:00
|
|
|
|
private readonly IWellboreService wellboreService;
|
2023-08-14 18:30:31 +05:00
|
|
|
|
|
2023-08-15 14:20:28 +05:00
|
|
|
|
public WellboreController(IWellboreService wellboreService)
|
2023-08-14 18:30:31 +05:00
|
|
|
|
{
|
2023-08-15 14:20:28 +05:00
|
|
|
|
this.wellboreService = wellboreService;
|
2023-08-14 18:30:31 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение ствола скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
2023-08-15 12:28:39 +05:00
|
|
|
|
/// <param name="idSection">Id типа секции скважины</param>
|
2023-08-14 18:30:31 +05:00
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2023-08-15 12:28:39 +05:00
|
|
|
|
[HttpGet("{idWell:int}/{idSection:int}")]
|
|
|
|
|
[ProducesResponseType(typeof(WellboreDto), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
2023-08-14 18:30:31 +05:00
|
|
|
|
{
|
2023-08-15 14:20:28 +05:00
|
|
|
|
var wellbore = await wellboreService.GetWellboreAsync(idWell, idSection, cancellationToken);
|
2023-08-15 12:28:39 +05:00
|
|
|
|
|
|
|
|
|
if (wellbore is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
return Ok(wellbore);
|
2023-08-14 18:30:31 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка стволов скважин
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">Пары идентификаторов скважины и секции</param>
|
|
|
|
|
/// <param name="skip">Опциональный параметр. Количество пропускаемых записей</param>
|
|
|
|
|
/// <param name="take">Опциональный параметр. Количество получаемых записей</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2023-08-15 12:28:39 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellboreDto>), StatusCodes.Status200OK)]
|
2023-08-14 18:30:31 +05:00
|
|
|
|
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
|
|
|
|
int? skip,
|
|
|
|
|
int? take,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var request = new WellboreRequest
|
|
|
|
|
{
|
2023-08-15 16:08:51 +05:00
|
|
|
|
Ids = ids.Select(id => ParseId(id)),
|
2023-08-14 18:30:31 +05:00
|
|
|
|
Skip = skip,
|
|
|
|
|
Take = take
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-15 14:20:28 +05:00
|
|
|
|
return Ok(await wellboreService.GetWellboresAsync(request, cancellationToken));
|
2023-08-14 18:30:31 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 16:08:51 +05:00
|
|
|
|
private static (int, int?) ParseId(string id)
|
|
|
|
|
{
|
|
|
|
|
var idPair = id.Split(',');
|
|
|
|
|
if (!int.TryParse(idPair[0], out var idWell))
|
2023-09-29 12:06:46 +05:00
|
|
|
|
throw new ArgumentInvalidException(nameof(id), $"Не удалось получить Id скважины \"{idPair[0]}\"");
|
2023-08-14 18:30:31 +05:00
|
|
|
|
|
2023-08-15 16:08:51 +05:00
|
|
|
|
if (idPair.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(idPair[1], out int idWellSectionType))
|
|
|
|
|
return (idWell, idWellSectionType);
|
|
|
|
|
else
|
2023-09-29 12:06:46 +05:00
|
|
|
|
throw new ArgumentInvalidException(nameof(id), $"Не удалось получить Id ствола \"{idPair[1]}\"");
|
2023-08-15 16:08:51 +05:00
|
|
|
|
}
|
|
|
|
|
return (idWell, null);
|
|
|
|
|
}
|
2023-08-14 18:30:31 +05:00
|
|
|
|
}
|