From 873b6d99a0c552aed3b845901b69180ad803299c Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 8 Aug 2024 14:29:59 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=BF=D0=BE=20=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D1=83=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Requests/WellContactRequest.cs | 20 +++++++++++ AsbCloudApp/Services/IWellContactService.cs | 8 ++--- .../Services/WellContactService.cs | 16 ++++++--- .../Controllers/WellContactController.cs | 36 +++++++++++++++++-- 4 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 AsbCloudApp/Requests/WellContactRequest.cs diff --git a/AsbCloudApp/Requests/WellContactRequest.cs b/AsbCloudApp/Requests/WellContactRequest.cs new file mode 100644 index 00000000..b2b18fa6 --- /dev/null +++ b/AsbCloudApp/Requests/WellContactRequest.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace AsbCloudApp.Requests +{ + /// + /// Запрос на контактов + /// + public class WellContactRequest + { + /// + /// Идентификаторы скважин + /// + public IEnumerable IdsWells { get; set; } = null!; + + /// + /// Ключ типа контактов + /// + public int? ContactTypeId { get; set; } + } +} diff --git a/AsbCloudApp/Services/IWellContactService.cs b/AsbCloudApp/Services/IWellContactService.cs index 266da573..cf7124db 100644 --- a/AsbCloudApp/Services/IWellContactService.cs +++ b/AsbCloudApp/Services/IWellContactService.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Data.User; +using AsbCloudApp.Requests; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -12,13 +13,12 @@ namespace AsbCloudApp.Services public interface IWellContactService { /// - /// Получение контактов по ключу скважины и типу контакта + /// Получение контактов по параметрам запроса /// - /// ключ скважины - /// тип контакта + /// ключ скважины /// /// - Task> GetAllAsync(int idWell, int contactTypeId, CancellationToken token); + Task> GetAllAsync(WellContactRequest request, CancellationToken token); /// /// Получение контакта по ключу diff --git a/AsbCloudInfrastructure/Services/WellContactService.cs b/AsbCloudInfrastructure/Services/WellContactService.cs index 1bb45b77..8fb7b6e6 100644 --- a/AsbCloudInfrastructure/Services/WellContactService.cs +++ b/AsbCloudInfrastructure/Services/WellContactService.cs @@ -1,6 +1,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Data.User; using AsbCloudApp.Exceptions; +using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; @@ -21,14 +22,19 @@ namespace AsbCloudInfrastructure.Services this.db = db; } - public async Task> GetAllAsync(int wellId, int contactTypeId, CancellationToken token) + public async Task> GetAllAsync(WellContactRequest request, CancellationToken token) { var query = db.Contacts - .Where(c => c.IdCompanyType == contactTypeId) - .Where(c => c.IdWell == wellId) - .Select(c => c.Adapt()); + .Where(c => request.IdsWells.Contains(c.IdWell)); - var entities = await query.AsNoTracking() + if (request.ContactTypeId.HasValue) + { + query = query.Where(c => c.IdCompanyType == request.ContactTypeId); + }; + + var dtos = query.Select(c => c.Adapt()); + + var entities = await dtos.AsNoTracking() .ToArrayAsync(token); return entities; diff --git a/AsbCloudWebApi/Controllers/WellContactController.cs b/AsbCloudWebApi/Controllers/WellContactController.cs index bdb6a7ae..6efe55b1 100644 --- a/AsbCloudWebApi/Controllers/WellContactController.cs +++ b/AsbCloudWebApi/Controllers/WellContactController.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Data.User; +using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.AspNetCore.Authorization; @@ -49,12 +50,43 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet("type/{contactTypeId}")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetAllAsync(int idWell, int contactTypeId, CancellationToken token) + public async Task GetByTypeAsync(int idWell, int contactTypeId, CancellationToken token) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await wellContactsRepository.GetAllAsync(idWell, contactTypeId, token); + var request = new WellContactRequest() + { + IdsWells = new int[] { idWell }, + ContactTypeId = contactTypeId + }; + + var result = await wellContactsRepository.GetAllAsync(request, token); + return Ok(result); + } + + /// + /// Получение контактов по массиву ключей скважины + /// + /// ключи скважин + /// + /// + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetAllAsync([FromQuery] IEnumerable idsWells, CancellationToken token) + { + foreach(var idWell in idsWells) + { + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) + return Forbid(); + } + + var request = new WellContactRequest() + { + IdsWells = idsWells + }; + + var result = await wellContactsRepository.GetAllAsync(request, token); return Ok(result); } From 58e02aca7485a4bbcb05866d564b210c491e0322 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 8 Aug 2024 14:32:08 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B9=20=D0=BA=20WellContactRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Requests/WellContactRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudApp/Requests/WellContactRequest.cs b/AsbCloudApp/Requests/WellContactRequest.cs index b2b18fa6..26fd4f1b 100644 --- a/AsbCloudApp/Requests/WellContactRequest.cs +++ b/AsbCloudApp/Requests/WellContactRequest.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace AsbCloudApp.Requests { /// - /// Запрос на контактов + /// Запрос на получение контактов /// public class WellContactRequest { From 9ab816cb4695ba02b132490cec3e0a69a798111f Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 8 Aug 2024 15:37:56 +0500 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/Services/WellContactService.cs | 8 ++++---- AsbCloudWebApi/Controllers/WellContactController.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellContactService.cs b/AsbCloudInfrastructure/Services/WellContactService.cs index 8fb7b6e6..770375f3 100644 --- a/AsbCloudInfrastructure/Services/WellContactService.cs +++ b/AsbCloudInfrastructure/Services/WellContactService.cs @@ -32,12 +32,12 @@ namespace AsbCloudInfrastructure.Services query = query.Where(c => c.IdCompanyType == request.ContactTypeId); }; - var dtos = query.Select(c => c.Adapt()); - - var entities = await dtos.AsNoTracking() + var entities = await query.AsNoTracking() .ToArrayAsync(token); - return entities; + var dtos = entities.Select(c => c.Adapt()); + + return dtos; } public async Task GetAsync(int idWell, int id, CancellationToken token) diff --git a/AsbCloudWebApi/Controllers/WellContactController.cs b/AsbCloudWebApi/Controllers/WellContactController.cs index 6efe55b1..1bd43564 100644 --- a/AsbCloudWebApi/Controllers/WellContactController.cs +++ b/AsbCloudWebApi/Controllers/WellContactController.cs @@ -71,7 +71,7 @@ namespace AsbCloudWebApi.Controllers /// ключи скважин /// /// - [HttpGet] + [HttpGet("/api/well/[controller]")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetAllAsync([FromQuery] IEnumerable idsWells, CancellationToken token) {