forked from ddrilling/AsbCloudServer
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// Инфо о месторождениях
|
||
/// </summary>
|
||
[Route("api/deposit")]
|
||
[ApiController]
|
||
[Authorize]
|
||
public class DepositController : ControllerBase
|
||
{
|
||
private readonly IDepositRepository depositService;
|
||
|
||
public DepositController(IDepositRepository depositService)
|
||
{
|
||
this.depositService = depositService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получает список доступных пользователю месторождений
|
||
/// </summary>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> 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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получает список доступных пользователю кустов месторождения
|
||
/// </summary>
|
||
/// <param name="depositId"></param>
|
||
/// <param name="token"> Токен отмены задачи </param>
|
||
/// <returns></returns>
|
||
[HttpGet("{depositId}")]
|
||
[Permission]
|
||
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public async Task<IActionResult> 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);
|
||
}
|
||
|
||
}
|
||
}
|