From 0230432c8ca62ecf25052a36d063b54f589a59e5 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 5 Jul 2023 14:22:22 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20We?= =?UTF-8?q?llController.GetOrDefaultStatAsync(..)=20=D1=81=20=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD=D0=B5?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IWellService.cs | 8 +++++++ .../Services/WellService.cs | 17 ++++++++++++++ AsbCloudWebApi/Controllers/WellController.cs | 22 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index eb8d9f37..7c1cc8fd 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -102,5 +102,13 @@ namespace AsbCloudApp.Services /// /// Task> GetWellTreeAsync(int idCompany, CancellationToken token); + + /// + /// Статистика по скважине + /// + /// + /// + /// + Task GetOrDefaultStatAsync(int idWell, CancellationToken token); } } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 6d70dd9c..4cf88d82 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -103,6 +103,23 @@ namespace AsbCloudInfrastructure.Services return depositTree; } + public async Task GetOrDefaultStatAsync(int idWell, CancellationToken token) + { + var dto = wellInfoService.FirstOrDefault(well => well.Id == idWell); + if (dto is not null) + return dto; + + var request = new WellRequest{Ids = new[] { idWell }}; + var entities = await GetEntitiesAsync(request, token); + var entity = entities.FirstOrDefault(); + if (entity is null) + return null; + + dto = entity.Adapt(); + + return dto; + } + public async Task> GetAsync(WellRequest request, CancellationToken token) { var wells = await GetEntitiesAsync(request, token); diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index db69f959..30b259c8 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -88,6 +88,28 @@ namespace AsbCloudWebApi.Controllers return Ok(well); } + /// + /// Возвращает информацию о требуемой скважине + /// + /// Id требуемой скважины + /// Токен отмены задачи + /// Информация о требуемой скважине + [HttpGet("{idWell}/info")] + [Permission] + [ProducesResponseType(typeof(WellDto), (int)System.Net.HttpStatusCode.OK)] + public async Task GetStatAsync(int idWell, CancellationToken token) + { + var idCompany = User.GetCompanyId(); + + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false)) + return Forbid(); + + var well = await wellService.GetOrDefaultStatAsync(idWell, + token); + + return Ok(well); + } + /// /// Редактирует указанные поля скважины ///