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/cluster")]
|
2021-07-19 15:11:01 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class ClusterController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IClusterService clusterService;
|
|
|
|
|
|
|
|
|
|
public ClusterController(IClusterService clusterService)
|
|
|
|
|
{
|
|
|
|
|
this.clusterService = clusterService;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 15:57:51 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает список доступных пользователю кустов
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet()]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetClustersAsync()
|
2021-07-19 15:57:51 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-07-19 15:57:51 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (idCompany is null)
|
2021-07-19 15:57:51 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 12:11:21 +05:00
|
|
|
|
var result = await clusterService.GetClustersAsync((int)idCompany);
|
2021-07-19 15:57:51 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 15:11:01 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение доступных пользователю скважин
|
|
|
|
|
/// </summary>
|
2021-07-21 15:29:19 +05:00
|
|
|
|
/// <param name="idCluster"></param>
|
2021-07-19 15:11:01 +05:00
|
|
|
|
/// <returns></returns>
|
2021-07-21 15:29:19 +05:00
|
|
|
|
[HttpGet("{idCluster}")]
|
2021-07-19 15:11:01 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetWellsAsync(int idCluster)
|
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.GetWellsAsync((int)idCompany, idCluster);
|
2021-07-19 15:11:01 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-07-21 15:29:19 +05:00
|
|
|
|
/// Получение обопщенной статистики по кусту (лучшая/худшая скважина)
|
2021-07-19 15:11:01 +05:00
|
|
|
|
/// </summary>
|
2021-07-21 15:29:19 +05:00
|
|
|
|
/// <param name="idCluster"></param>
|
2021-07-19 15:11:01 +05:00
|
|
|
|
/// <returns></returns>
|
2021-07-21 15:29:19 +05:00
|
|
|
|
[HttpGet("{idCluster}/Stat")]
|
2021-07-21 18:03:45 +05:00
|
|
|
|
[ProducesResponseType(typeof(ClusterStatDto), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetStatAsync(int idCluster)
|
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.GetStatAsync((int)idCompany, idCluster);
|
2021-07-19 15:11:01 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|