forked from ddrilling/AsbCloudServer
78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[Route("api/well")]
|
|
[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)]
|
|
public async Task<IActionResult> GetWellsAsync()
|
|
{
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
if (idCompany is null)
|
|
{
|
|
return NoContent();
|
|
}
|
|
|
|
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany);
|
|
|
|
if (wells is null || !wells.Any())
|
|
return NoContent();
|
|
|
|
return Ok(wells);
|
|
}
|
|
|
|
[HttpGet("{idWell}/operations")]
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetOperationsAsync(int idWell)
|
|
{
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
if (idCompany is null)
|
|
return NoContent();
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
|
return Forbid();
|
|
|
|
var dto = await wellService.GetOperationsAsync(idWell);
|
|
|
|
return Ok(dto);
|
|
}
|
|
|
|
[HttpGet("transmittingWells")]
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetTransmittingWellsAsync()
|
|
{
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
if (idCompany is null)
|
|
return NoContent();
|
|
|
|
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany);
|
|
|
|
if (transmittingWells is null || !transmittingWells.Any())
|
|
return NoContent();
|
|
|
|
return Ok(transmittingWells);
|
|
|
|
}
|
|
}
|
|
}
|