DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/WellController.cs

78 lines
2.2 KiB
C#
Raw Normal View History

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
{
2021-04-07 18:01:56 +05:00
[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()
{
2021-07-21 15:22:58 +05:00
var idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
if (idCompany is null)
{
return NoContent();
}
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany);
if (wells is null || !wells.Any())
return NoContent();
return Ok(wells);
}
2021-07-27 14:43:30 +05:00
[HttpGet("{idWell}/operations")]
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsAsync(int idWell)
2021-07-27 13:32:00 +05:00
{
var idCompany = User.GetCompanyId();
if (idCompany is null)
return NoContent();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
2021-07-27 13:32:00 +05:00
return Forbid();
var dto = await wellService.GetOperationsAsync(idWell);
2021-07-27 13:32:00 +05:00
return Ok(dto);
}
[HttpGet("transmittingWells")]
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetTransmittingWellsAsync()
{
2021-07-21 15:22:58 +05:00
var idCompany = User.GetCompanyId();
2021-07-21 15:29:19 +05:00
if (idCompany is null)
return NoContent();
2021-07-21 15:29:19 +05:00
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany);
if (transmittingWells is null || !transmittingWells.Any())
return NoContent();
return Ok(transmittingWells);
2021-07-21 15:29:19 +05:00
}
}
}