forked from ddrilling/AsbCloudServer
68 lines
2.2 KiB
C#
68 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.Threading;
|
||
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>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns></returns>
|
||
[HttpGet()]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> 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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получение доступных пользователю скважин
|
||
/// </summary>
|
||
/// <param name="idCluster"></param>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns></returns>
|
||
[HttpGet("{idCluster}")]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> 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);
|
||
}
|
||
}
|
||
}
|