DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/DepositController.cs

69 lines
2.1 KiB
C#
Raw Permalink Normal View History

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;
2024-08-19 10:01:07 +05:00
namespace AsbCloudWebApi.Controllers;
/// <summary>
/// Инфо о месторождениях
/// </summary>
[Route("api/deposit")]
[ApiController]
[Authorize]
public class DepositController : ControllerBase
{
2024-08-19 10:01:07 +05:00
private readonly IDepositRepository depositService;
public DepositController(IDepositRepository depositService)
{
this.depositService = depositService;
}
/// <summary>
2024-08-19 10:01:07 +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)
{
2024-08-19 10:01:07 +05:00
int? idCompany = User.GetCompanyId();
2024-08-19 10:01:07 +05:00
if (idCompany is null)
return Forbid();
2024-08-19 10:01:07 +05:00
var result = await depositService.GetAsync((int)idCompany,
token).ConfigureAwait(false);
return Ok(result);
}
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();
2024-08-19 10:01:07 +05:00
if (idCompany is null)
return Forbid();
2024-08-19 10:01:07 +05:00
var result = await depositService.GetClustersAsync((int)idCompany,
depositId, token).ConfigureAwait(false);
return Ok(result);
}
2024-08-19 10:01:07 +05:00
}