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

82 lines
2.6 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер кустов
/// </summary>
[Route("api/cluster")]
[ApiController]
[Authorize]
public class ClusterController : ControllerBase
{
private readonly IClusterService clusterService;
public ClusterController(IClusterService clusterService)
{
this.clusterService = clusterService;
}
/// <summary>
/// Получает список доступных пользователю кустов
/// </summary>
/// <returns></returns>
[HttpGet()]
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetClusters()
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetClusters((int)idCustomer);
return Ok(result);
}
/// <summary>
/// Получение доступных пользователю скважин
/// </summary>
/// <param name="clusterId"></param>
/// <returns></returns>
[HttpGet("{clusterId}")]
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWells(int clusterId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetWells((int)idCustomer, clusterId);
return Ok(result);
}
/// <summary>
/// Получение обопщенной аналитики по кусту (лучшая/худшая скважина)
/// </summary>
/// <param name="clusterId"></param>
/// <returns></returns>
[HttpGet("{clusterId}/Analysis")]
[ProducesResponseType(typeof(IEnumerable<ClusterAnalysisDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetAnalysis(int clusterId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetAnalysis((int)idCustomer, clusterId);
return Ok(result);
}
}
}