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-07-02 15:02:56 +05:00
|
|
|
|
using System.Linq;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[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
|
|
|
|
|
2021-07-02 15:02:56 +05:00
|
|
|
|
if (wells is null || !wells.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
return Ok(wells);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 16:03:14 +05:00
|
|
|
|
[HttpGet("transmittingWells")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> GetTransmittingWellsAsync(CancellationToken token = default)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
2021-05-12 16:03:14 +05:00
|
|
|
|
|
2021-07-21 15:29:19 +05:00
|
|
|
|
if (idCompany is null)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
return NoContent();
|
2021-07-21 15:29:19 +05:00
|
|
|
|
|
2021-08-24 10:59:10 +05:00
|
|
|
|
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
token).ConfigureAwait(false);
|
2021-05-12 16:03:14 +05:00
|
|
|
|
|
2021-07-02 15:02:56 +05:00
|
|
|
|
if (transmittingWells is null || !transmittingWells.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-05-12 16:03:14 +05:00
|
|
|
|
return Ok(transmittingWells);
|
2021-07-21 15:29:19 +05:00
|
|
|
|
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|