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

79 lines
2.6 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер кустов
/// </summary>
[Route("api/cluster")]
[ApiController]
[Authorize]
public class ClusterController : ControllerBase
{
private readonly IClusterService clusterService;
public ClusterController(IClusterService clusterService)
{
this.clusterService = clusterService;
}
/// <summary>
/// Получает список доступных пользователю кустов
/// </summary>
/// <returns></returns>
[HttpGet()]
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetClustersAsync()
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var result = await clusterService.GetClustersAsync((int)idCompany);
return Ok(result);
}
/// <summary>
/// Получение доступных пользователю скважин
/// </summary>
/// <param name="idCluster"></param>
/// <returns></returns>
[HttpGet("{idCluster}")]
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetWellsAsync(int idCluster)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var result = await clusterService.GetWellsAsync((int)idCompany, idCluster);
return Ok(result);
}
/// <summary>
/// Получение обопщенной статистики по кусту (лучшая/худшая скважина)
/// </summary>
/// <param name="idCluster"></param>
/// <returns></returns>
[HttpGet("{idCluster}/Stat")]
[ProducesResponseType(typeof(ClusterStatDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatAsync(int idCluster)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var result = await clusterService.GetStatAsync((int)idCompany, idCluster);
return Ok(result);
}
}
}