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-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-04-30 17:35:35 +05:00
|
|
|
|
public IActionResult GetWells()
|
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-07-21 15:22:58 +05:00
|
|
|
|
var wells = wellService.GetWellsByCompany((int)idCompany);
|
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-07-27 14:43:30 +05:00
|
|
|
|
[HttpGet("{idWell}/operations")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetOperations(int idWell)
|
2021-07-27 13:32:00 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-07-29 12:39:22 +05:00
|
|
|
|
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
2021-07-27 13:32:00 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-07-27 14:43:30 +05:00
|
|
|
|
var dto = wellService.GetOperations(idWell);
|
2021-07-27 13:32:00 +05:00
|
|
|
|
|
|
|
|
|
return Ok(dto);
|
2021-07-27 12:37:10 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 16:03:14 +05:00
|
|
|
|
[HttpGet("transmittingWells")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetTransmittingWells()
|
|
|
|
|
{
|
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-07-21 15:22:58 +05:00
|
|
|
|
var transmittingWells = wellService.GetTransmittingWells((int)idCompany);
|
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
|
|
|
|
}
|
|
|
|
|
}
|