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

80 lines
2.1 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;
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 IActionResult GetWells()
{
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();
}
2021-07-21 15:22:58 +05:00
var wells = wellService.GetWellsByCompany((int)idCompany);
if (wells is null || !wells.Any())
return NoContent();
return Ok(wells);
}
[HttpGet("{wellId}/sections")]
[ProducesResponseType(typeof(IEnumerable<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetSections(int wellId)
{
var idCompany = User.GetCompanyId();
if (idCompany is null)
return NoContent();
if (wellService.IsCompanyOwnsWell((int)idCompany, wellId))
return Forbid();
var dto = wellService.GetStat(wellId, (int)idCompany);
return Ok(dto);
}
[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-07-21 15:29:19 +05:00
if (idCompany is null)
{
return NoContent();
}
2021-07-21 15:29:19 +05:00
2021-07-21 15:22:58 +05:00
var transmittingWells = wellService.GetTransmittingWells((int)idCompany);
if (transmittingWells is null || !transmittingWells.Any())
return NoContent();
return Ok(transmittingWells);
2021-07-21 15:29:19 +05:00
}
}
}