2021-07-19 15:11:01 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер для месторождений
|
|
|
|
|
/// </summary>
|
2021-07-19 15:57:51 +05:00
|
|
|
|
[Route("api/deposit")]
|
2021-07-19 15:11:01 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DepositController : ControllerBase
|
|
|
|
|
{
|
2021-07-21 17:23:57 +05:00
|
|
|
|
private readonly IClusterService clusterService;
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
|
|
|
|
public DepositController(IClusterService clusterService)
|
|
|
|
|
{
|
|
|
|
|
this.clusterService = clusterService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает список доступных пользователю месторождений
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetDepositsAsync()
|
2021-07-19 15:11:01 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (idCompany is null)
|
2021-07-19 15:11:01 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 12:11:21 +05:00
|
|
|
|
var result = await clusterService.GetDepositsAsync((int)idCompany);
|
2021-07-19 15:11:01 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает список доступных пользователю кустов месторождения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="depositId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{depositId}")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetClustersAsync(int depositId)
|
2021-07-19 15:11:01 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-07-19 15:11:01 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (idCompany is null)
|
2021-07-19 15:11:01 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 12:11:21 +05:00
|
|
|
|
var result = await clusterService.GetClustersAsync((int)idCompany, depositId);
|
2021-07-19 15:11:01 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|