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