using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
///
/// Контроллер кустов
///
[Route("api/cluster")]
[ApiController]
[Authorize]
public class ClusterController : ControllerBase
{
private readonly IClusterService clusterService;
public ClusterController(IClusterService clusterService)
{
this.clusterService = clusterService;
}
///
/// Получает список доступных пользователю кустов
///
/// Токен отмены задачи
///
[HttpGet()]
[Permission]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetClustersAsync(CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var result = await clusterService.GetClustersAsync((int)idCompany,
token).ConfigureAwait(false);
return Ok(result);
}
///
/// Получение доступных пользователю скважин
///
///
/// Токен отмены задачи
///
[HttpGet("{idCluster}")]
[Permission]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetWellsAsync(int idCluster, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var result = await clusterService.GetWellsAsync((int)idCompany,
idCluster, token).ConfigureAwait(false);
return Ok(result);
}
}
}