From 2228c841397a1532c492e7d52dcfba36938a82d4 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Wed, 4 Dec 2024 16:29:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Persistence.API/Controllers/SetpointController.cs | 7 ++++--- Persistence.API/Controllers/TechMessagesController.cs | 6 +----- .../Repositories/TechMessagesRepository.cs | 3 ++- Persistence/API/ISetpointApi.cs | 2 +- Persistence/Repositories/ITechMessagesRepository.cs | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Persistence.API/Controllers/SetpointController.cs b/Persistence.API/Controllers/SetpointController.cs index 1bae2c6..42a5ff5 100644 --- a/Persistence.API/Controllers/SetpointController.cs +++ b/Persistence.API/Controllers/SetpointController.cs @@ -101,10 +101,11 @@ public class SetpointController : ControllerBase, ISetpointApi /// /// [HttpPost] - [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] - public async Task Add(Guid setpointKey, object newValue, Guid idUser, CancellationToken token) + [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] + public async Task Add(Guid setpointKey, object newValue, CancellationToken token) { - await setpointRepository.Add(setpointKey, newValue, idUser, token); + var userId = User.GetUserId(); + await setpointRepository.Add(setpointKey, newValue, userId, token); return CreatedAtAction(nameof(Add), true); } diff --git a/Persistence.API/Controllers/TechMessagesController.cs b/Persistence.API/Controllers/TechMessagesController.cs index bb26c6a..d2691c1 100644 --- a/Persistence.API/Controllers/TechMessagesController.cs +++ b/Persistence.API/Controllers/TechMessagesController.cs @@ -110,12 +110,8 @@ public class TechMessagesController : ControllerBase public async Task AddRange([FromBody] IEnumerable dtos, CancellationToken token) { var userId = User.GetUserId(); - foreach (var dto in dtos) - { - dto.UserId = userId; - } - var result = await techMessagesRepository.AddRange(dtos, token); + var result = await techMessagesRepository.AddRange(dtos, userId, token); return CreatedAtAction(nameof(AddRange), result); } diff --git a/Persistence.Repository/Repositories/TechMessagesRepository.cs b/Persistence.Repository/Repositories/TechMessagesRepository.cs index 38d24e8..c838619 100644 --- a/Persistence.Repository/Repositories/TechMessagesRepository.cs +++ b/Persistence.Repository/Repositories/TechMessagesRepository.cs @@ -88,7 +88,7 @@ namespace Persistence.Repository.Repositories return result; } - public async Task AddRange(IEnumerable dtos, CancellationToken token) + public async Task AddRange(IEnumerable dtos, Guid userId, CancellationToken token) { var entities = new List(); @@ -100,6 +100,7 @@ namespace Persistence.Repository.Repositories ?? await CreateDrillingSystem(dto.System, token); entity.SystemId = systemId; + entity.UserId = userId; entities.Add(entity); } diff --git a/Persistence/API/ISetpointApi.cs b/Persistence/API/ISetpointApi.cs index 0d23d69..b1504a2 100644 --- a/Persistence/API/ISetpointApi.cs +++ b/Persistence/API/ISetpointApi.cs @@ -40,5 +40,5 @@ public interface ISetpointApi : ISyncApi /// значение /// /// - Task Add(Guid setpointKey, object newValue, Guid userId, CancellationToken token); + Task Add(Guid setpointKey, object newValue, CancellationToken token); } diff --git a/Persistence/Repositories/ITechMessagesRepository.cs b/Persistence/Repositories/ITechMessagesRepository.cs index 2ddf71c..92e8f70 100644 --- a/Persistence/Repositories/ITechMessagesRepository.cs +++ b/Persistence/Repositories/ITechMessagesRepository.cs @@ -22,7 +22,7 @@ namespace Persistence.Repositories /// /// /// - Task AddRange(IEnumerable dtos, CancellationToken token); + Task AddRange(IEnumerable dtos, Guid userId, CancellationToken token); /// /// Получение списка уникальных названий систем АБ