2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-12-23 14:35:23 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2021-07-19 15:11:01 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инфо о месторождениях
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/deposit")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DepositController : ControllerBase
|
2021-07-19 15:11:01 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IDepositRepository depositService;
|
|
|
|
|
|
|
|
|
|
public DepositController(IDepositRepository depositService)
|
|
|
|
|
{
|
|
|
|
|
this.depositService = depositService;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 15:11:01 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// Получает список доступных пользователю месторождений
|
2021-07-19 15:11:01 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetDepositsAsync(CancellationToken token)
|
2021-07-19 15:11:01 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var result = await depositService.GetAsync((int)idCompany,
|
|
|
|
|
token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <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();
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var result = await depositService.GetClustersAsync((int)idCompany,
|
|
|
|
|
depositId, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
2021-07-19 15:11:01 +05:00
|
|
|
|
}
|
2024-08-19 10:01:07 +05:00
|
|
|
|
|
2021-07-19 15:11:01 +05:00
|
|
|
|
}
|