From 00798becb0d7b9cae4d9852d4317972977be402f Mon Sep 17 00:00:00 2001 From: KharchenkoVladimir Date: Fri, 19 Nov 2021 11:12:25 +0500 Subject: [PATCH] CS2-107: Added ClusterOperationStatController --- AsbCloudApp/Data/ClusterMseStatDto.cs | 8 +++ .../ClusterOperationStatController.cs | 67 +++++++++++++++++++ .../WellOperationStatController.cs | 2 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 AsbCloudApp/Data/ClusterMseStatDto.cs create mode 100644 AsbCloudWebApi/Controllers/ClusterOperationStatController.cs diff --git a/AsbCloudApp/Data/ClusterMseStatDto.cs b/AsbCloudApp/Data/ClusterMseStatDto.cs new file mode 100644 index 00000000..4b3841ef --- /dev/null +++ b/AsbCloudApp/Data/ClusterMseStatDto.cs @@ -0,0 +1,8 @@ +namespace AsbCloudApp.Data +{ + public class ClusterMseStatDto + { + public double MseMax { get; set; } + public double MseAverage { get; set; } + } +} \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/ClusterOperationStatController.cs b/AsbCloudWebApi/Controllers/ClusterOperationStatController.cs new file mode 100644 index 00000000..139b2951 --- /dev/null +++ b/AsbCloudWebApi/Controllers/ClusterOperationStatController.cs @@ -0,0 +1,67 @@ +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.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudWebApi.Controllers +{ + /// + /// Контроллер статистики вручную внесенных операций на кусту + /// + [Route("api/cluster")] + [ApiController] + [Authorize] + public class ClusterOperationStatController : ControllerBase + { + private readonly IWellOperationService operationService; + private readonly IWellService wellService; + private readonly IWellOperationImportService wellOperationImportService; + + public ClusterOperationStatController(IWellOperationService operationService, + IWellService wellService, IWellOperationImportService wellOperationImportService) + { + this.operationService = operationService; + this.wellService = wellService; + this.wellOperationImportService = wellOperationImportService; + } + + /// + /// Формирует данные по среднему и максимальному МСП на кусту + /// + /// id скважины с данного куста (через нее будут полуены данные) + /// + /// Возвращает данные по среднему и максимальному МСП на кусту + [HttpGet("{idWell}/mseStat")] + [ProducesResponseType(typeof(ClusterMseStatDto), (int)System.Net.HttpStatusCode.OK)] + public async Task GetClusterMseStatAsync([FromRoute] int idWell, + CancellationToken token = default) + { + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) + return Forbid(); + + // var result = await operationService.GetOperationsAsync( + // idWell, token).ConfigureAwait(false); + + var result = new ClusterMseStatDto() + { + MseMax = 3.2, + MseAverage = 1.1 + }; + + return Ok(result); + } + + private async Task CanUserAccessToWellAsync(int idWell, CancellationToken token = default) + { + int? idCompany = User.GetCompanyId(); + return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/WellOperationStatController.cs b/AsbCloudWebApi/Controllers/WellOperationStatController.cs index 7d71cac3..f6235f8d 100644 --- a/AsbCloudWebApi/Controllers/WellOperationStatController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationStatController.cs @@ -33,7 +33,7 @@ namespace AsbCloudWebApi.Controllers /// /// [HttpGet] - [Route("cluster/{idCluster}/stat")] + [Route("cluster/{idCluster}/stat")] // TODO: Это статистика клатера, перенести в ClusterOperationStatController [ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)] public async Task GetStatClusterAsync(int idCluster, CancellationToken token = default)