From 7092324a5461ff6402de11484159a2eb4e0139f9 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Wed, 4 Dec 2024 14:18:57 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20Insert=20=D0=BD=D0=B0=20?= =?UTF-8?q?Add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Persistence.API/Controllers/SetpointController.cs | 6 +++--- Persistence.API/Controllers/TechMessagesController.cs | 6 +++--- Persistence.API/Controllers/TimeSeriesController.cs | 4 ++-- Persistence.API/Controllers/TimestampedSetController.cs | 4 ++-- Persistence.Repository/Repositories/SetpointRepository.cs | 2 +- .../Repositories/TechMessagesRepository.cs | 2 +- .../Repositories/TimeSeriesDataCachedRepository.cs | 4 ++-- .../Repositories/TimeSeriesDataRepository.cs | 2 +- .../Repositories/TimestampedSetRepository.cs | 2 +- Persistence/API/ISetpointApi.cs | 2 +- Persistence/API/ITimeSeriesDataApi.cs | 2 +- Persistence/Repositories/AbstractChangeLogRepository.cs | 2 +- Persistence/Repositories/ISetpointRepository.cs | 2 +- Persistence/Repositories/ITechMessagesRepository.cs | 2 +- Persistence/Repositories/ITimeSeriesDataRepository.cs | 2 +- Persistence/Repositories/ITimestampedSetRepository.cs | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Persistence.API/Controllers/SetpointController.cs b/Persistence.API/Controllers/SetpointController.cs index 108c3ef..1bae2c6 100644 --- a/Persistence.API/Controllers/SetpointController.cs +++ b/Persistence.API/Controllers/SetpointController.cs @@ -102,10 +102,10 @@ public class SetpointController : ControllerBase, ISetpointApi /// [HttpPost] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] - public async Task Save(Guid setpointKey, object newValue, Guid idUser, CancellationToken token) + public async Task Add(Guid setpointKey, object newValue, Guid idUser, CancellationToken token) { - await setpointRepository.Save(setpointKey, newValue, idUser, token); + await setpointRepository.Add(setpointKey, newValue, idUser, token); - return Ok(); + return CreatedAtAction(nameof(Add), true); } } diff --git a/Persistence.API/Controllers/TechMessagesController.cs b/Persistence.API/Controllers/TechMessagesController.cs index 4e91802..bb26c6a 100644 --- a/Persistence.API/Controllers/TechMessagesController.cs +++ b/Persistence.API/Controllers/TechMessagesController.cs @@ -107,7 +107,7 @@ public class TechMessagesController : ControllerBase /// [HttpPost] [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] - public async Task InsertRange([FromBody] IEnumerable dtos, CancellationToken token) + public async Task AddRange([FromBody] IEnumerable dtos, CancellationToken token) { var userId = User.GetUserId(); foreach (var dto in dtos) @@ -115,9 +115,9 @@ public class TechMessagesController : ControllerBase dto.UserId = userId; } - var result = await techMessagesRepository.InsertRange(dtos, token); + var result = await techMessagesRepository.AddRange(dtos, token); - return CreatedAtAction(nameof(InsertRange), result); + return CreatedAtAction(nameof(AddRange), result); } /// diff --git a/Persistence.API/Controllers/TimeSeriesController.cs b/Persistence.API/Controllers/TimeSeriesController.cs index 90c78c8..6991759 100644 --- a/Persistence.API/Controllers/TimeSeriesController.cs +++ b/Persistence.API/Controllers/TimeSeriesController.cs @@ -66,9 +66,9 @@ public class TimeSeriesController : ControllerBase, ITimeSeriesDataApi /// [HttpPost] - public async Task InsertRange(IEnumerable dtos, CancellationToken token) + public async Task AddRange(IEnumerable dtos, CancellationToken token) { - var result = await timeSeriesDataRepository.InsertRange(dtos, token); + var result = await timeSeriesDataRepository.AddRange(dtos, token); return Ok(result); } diff --git a/Persistence.API/Controllers/TimestampedSetController.cs b/Persistence.API/Controllers/TimestampedSetController.cs index f18e4c8..bd0e97e 100644 --- a/Persistence.API/Controllers/TimestampedSetController.cs +++ b/Persistence.API/Controllers/TimestampedSetController.cs @@ -32,9 +32,9 @@ public class TimestampedSetController : ControllerBase /// кол-во затронутых записей [HttpPost] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] - public async Task InsertRange([FromRoute]Guid idDiscriminator, [FromBody]IEnumerable sets, CancellationToken token) + public async Task AddRange([FromRoute]Guid idDiscriminator, [FromBody]IEnumerable sets, CancellationToken token) { - var result = await repository.InsertRange(idDiscriminator, sets, token); + var result = await repository.AddRange(idDiscriminator, sets, token); return Ok(result); } diff --git a/Persistence.Repository/Repositories/SetpointRepository.cs b/Persistence.Repository/Repositories/SetpointRepository.cs index b4557aa..8f0492c 100644 --- a/Persistence.Repository/Repositories/SetpointRepository.cs +++ b/Persistence.Repository/Repositories/SetpointRepository.cs @@ -88,7 +88,7 @@ namespace Persistence.Repository.Repositories return dtos; } - public async Task Save(Guid setpointKey, object newValue, Guid idUser, CancellationToken token) + public async Task Add(Guid setpointKey, object newValue, Guid idUser, CancellationToken token) { var entity = new Setpoint() { diff --git a/Persistence.Repository/Repositories/TechMessagesRepository.cs b/Persistence.Repository/Repositories/TechMessagesRepository.cs index fad8acf..04bab02 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 InsertRange(IEnumerable dtos, CancellationToken token) + public async Task AddRange(IEnumerable dtos, CancellationToken token) { var entities = new List(); diff --git a/Persistence.Repository/Repositories/TimeSeriesDataCachedRepository.cs b/Persistence.Repository/Repositories/TimeSeriesDataCachedRepository.cs index 20dbe00..2037f09 100644 --- a/Persistence.Repository/Repositories/TimeSeriesDataCachedRepository.cs +++ b/Persistence.Repository/Repositories/TimeSeriesDataCachedRepository.cs @@ -48,9 +48,9 @@ public class TimeSeriesDataCachedRepository : TimeSeriesDataRepos return items; } - public override async Task InsertRange(IEnumerable dtos, CancellationToken token) + public override async Task AddRange(IEnumerable dtos, CancellationToken token) { - var result = await base.InsertRange(dtos, token); + var result = await base.AddRange(dtos, token); if (result > 0) { diff --git a/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs b/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs index d73caf7..0e58c76 100644 --- a/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs +++ b/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs @@ -41,7 +41,7 @@ public class TimeSeriesDataRepository : ITimeSeriesDataRepository return dtos; } - public virtual async Task InsertRange(IEnumerable dtos, CancellationToken token) + public virtual async Task AddRange(IEnumerable dtos, CancellationToken token) { var entities = dtos.Select(d => d.Adapt()); diff --git a/Persistence.Repository/Repositories/TimestampedSetRepository.cs b/Persistence.Repository/Repositories/TimestampedSetRepository.cs index ad9a6cf..a67b823 100644 --- a/Persistence.Repository/Repositories/TimestampedSetRepository.cs +++ b/Persistence.Repository/Repositories/TimestampedSetRepository.cs @@ -20,7 +20,7 @@ public class TimestampedSetRepository : ITimestampedSetRepository this.db = db; } - public Task InsertRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token) + public Task AddRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token) { var entities = sets.Select(set => new TimestampedSet(idDiscriminator, set.Timestamp.ToUniversalTime(), set.Set)); var dbSet = db.Set(); diff --git a/Persistence/API/ISetpointApi.cs b/Persistence/API/ISetpointApi.cs index d05fe12..0d23d69 100644 --- a/Persistence/API/ISetpointApi.cs +++ b/Persistence/API/ISetpointApi.cs @@ -40,5 +40,5 @@ public interface ISetpointApi : ISyncApi /// значение /// /// - Task Save(Guid setpointKey, object newValue, Guid userId, CancellationToken token); + Task Add(Guid setpointKey, object newValue, Guid userId, CancellationToken token); } diff --git a/Persistence/API/ITimeSeriesDataApi.cs b/Persistence/API/ITimeSeriesDataApi.cs index a2406aa..51b9332 100644 --- a/Persistence/API/ITimeSeriesDataApi.cs +++ b/Persistence/API/ITimeSeriesDataApi.cs @@ -28,7 +28,7 @@ public interface ITimeSeriesDataApi : ITimeSeriesBaseDataApi /// /// /// - Task InsertRange(IEnumerable dtos, CancellationToken token); + Task AddRange(IEnumerable dtos, CancellationToken token); } diff --git a/Persistence/Repositories/AbstractChangeLogRepository.cs b/Persistence/Repositories/AbstractChangeLogRepository.cs index 88cf511..d7b1cbc 100644 --- a/Persistence/Repositories/AbstractChangeLogRepository.cs +++ b/Persistence/Repositories/AbstractChangeLogRepository.cs @@ -74,7 +74,7 @@ namespace Persistence.Repositories; // throw new NotImplementedException(); // } -// public async Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token) +// public async Task AddRange(int idUser, IEnumerable dtos, CancellationToken token) // { // using var transaction = dbContext.Database.BeginTransaction(); // try diff --git a/Persistence/Repositories/ISetpointRepository.cs b/Persistence/Repositories/ISetpointRepository.cs index 1fe41de..502b44a 100644 --- a/Persistence/Repositories/ISetpointRepository.cs +++ b/Persistence/Repositories/ISetpointRepository.cs @@ -59,5 +59,5 @@ public interface ISetpointRepository /// /// to do /// id User учесть в соответствующем методе репозитория - Task Save(Guid setpointKey, object newValue, Guid idUser, CancellationToken token); + Task Add(Guid setpointKey, object newValue, Guid idUser, CancellationToken token); } diff --git a/Persistence/Repositories/ITechMessagesRepository.cs b/Persistence/Repositories/ITechMessagesRepository.cs index 853f234..2ddf71c 100644 --- a/Persistence/Repositories/ITechMessagesRepository.cs +++ b/Persistence/Repositories/ITechMessagesRepository.cs @@ -22,7 +22,7 @@ namespace Persistence.Repositories /// /// /// - Task InsertRange(IEnumerable dtos, CancellationToken token); + Task AddRange(IEnumerable dtos, CancellationToken token); /// /// Получение списка уникальных названий систем АБ diff --git a/Persistence/Repositories/ITimeSeriesDataRepository.cs b/Persistence/Repositories/ITimeSeriesDataRepository.cs index 9de7fc7..aa2c9ff 100644 --- a/Persistence/Repositories/ITimeSeriesDataRepository.cs +++ b/Persistence/Repositories/ITimeSeriesDataRepository.cs @@ -15,5 +15,5 @@ public interface ITimeSeriesDataRepository : ISyncRepository, ITimeS /// /// /// - Task InsertRange(IEnumerable dtos, CancellationToken token); + Task AddRange(IEnumerable dtos, CancellationToken token); } diff --git a/Persistence/Repositories/ITimestampedSetRepository.cs b/Persistence/Repositories/ITimestampedSetRepository.cs index 27627c3..c350739 100644 --- a/Persistence/Repositories/ITimestampedSetRepository.cs +++ b/Persistence/Repositories/ITimestampedSetRepository.cs @@ -55,5 +55,5 @@ public interface ITimestampedSetRepository /// /// /// - Task InsertRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token); + Task AddRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token); } \ No newline at end of file From dd888793fd5d4a54cdd63400b5d62d3534ba4d8d Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Wed, 4 Dec 2024 14:44:33 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=80=D0=B5=D0=B2?= =?UTF-8?q?=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Persistence.Client/Clients/ISetpointClient.cs | 2 +- .../Clients/ITechMessagesClient.cs | 2 +- .../Clients/ITimeSeriesClient.cs | 2 +- .../Clients/ITimestampedSetClient.cs | 2 +- .../Controllers/SetpointControllerTest.cs | 41 +++++++++++++------ .../Controllers/TechMessagesControllerTest.cs | 4 +- .../TimeSeriesBaseControllerTest.cs | 2 +- .../TimestampedSetControllerTest.cs | 18 ++++---- .../Repositories/SetpointRepository.cs | 2 +- .../Repositories/TechMessagesRepository.cs | 2 +- 10 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Persistence.Client/Clients/ISetpointClient.cs b/Persistence.Client/Clients/ISetpointClient.cs index 886e034..0b81ffa 100644 --- a/Persistence.Client/Clients/ISetpointClient.cs +++ b/Persistence.Client/Clients/ISetpointClient.cs @@ -26,5 +26,5 @@ public interface ISetpointClient Task>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token); [Post($"{BaseRoute}/")] - Task Save(Guid setpointKey, object newValue); + Task Add(Guid setpointKey, object newValue); } diff --git a/Persistence.Client/Clients/ITechMessagesClient.cs b/Persistence.Client/Clients/ITechMessagesClient.cs index cbdf7ef..878c6cf 100644 --- a/Persistence.Client/Clients/ITechMessagesClient.cs +++ b/Persistence.Client/Clients/ITechMessagesClient.cs @@ -14,7 +14,7 @@ namespace Persistence.Client.Clients Task>> GetPage([Query] RequestDto request, CancellationToken token); [Post($"{BaseRoute}")] - Task> InsertRange([Body] IEnumerable dtos, CancellationToken token); + Task> AddRange([Body] IEnumerable dtos, CancellationToken token); [Get($"{BaseRoute}/systems")] Task>> GetSystems(CancellationToken token); diff --git a/Persistence.Client/Clients/ITimeSeriesClient.cs b/Persistence.Client/Clients/ITimeSeriesClient.cs index 349337b..8e97836 100644 --- a/Persistence.Client/Clients/ITimeSeriesClient.cs +++ b/Persistence.Client/Clients/ITimeSeriesClient.cs @@ -8,7 +8,7 @@ public interface ITimeSeriesClient private const string BaseRoute = "/api/dataSaub"; [Post($"{BaseRoute}")] - Task> InsertRange(IEnumerable dtos); + Task> AddRange(IEnumerable dtos); [Get($"{BaseRoute}")] Task>> Get(DateTimeOffset dateBegin, DateTimeOffset dateEnd); diff --git a/Persistence.Client/Clients/ITimestampedSetClient.cs b/Persistence.Client/Clients/ITimestampedSetClient.cs index 95e8bd1..bbff603 100644 --- a/Persistence.Client/Clients/ITimestampedSetClient.cs +++ b/Persistence.Client/Clients/ITimestampedSetClient.cs @@ -20,7 +20,7 @@ public interface ITimestampedSetClient /// /// [Post(baseUrl)] - Task> InsertRange(Guid idDiscriminator, IEnumerable sets); + Task> AddRange(Guid idDiscriminator, IEnumerable sets); /// /// Получение данных с фильтрацией. Значение фильтра null - отключен diff --git a/Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs b/Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs index d314cec..2c455a0 100644 --- a/Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs @@ -1,4 +1,5 @@ using System.Net; +using Microsoft.AspNetCore.Mvc.TagHelpers.Cache; using Microsoft.Extensions.DependencyInjection; using Persistence.Client; using Persistence.Client.Clients; @@ -47,7 +48,7 @@ namespace Persistence.IntegrationTests.Controllers public async Task GetCurrent_AfterSave_returns_success() { //arrange - var setpointKey = await Save(); + var setpointKey = await Add(); //act var response = await setpointClient.GetCurrent([setpointKey]); @@ -83,7 +84,7 @@ namespace Persistence.IntegrationTests.Controllers public async Task GetHistory_AfterSave_returns_success() { //arrange - var setpointKey = await Save(); + var setpointKey = await Add(); var historyMoment = DateTimeOffset.UtcNow; historyMoment = historyMoment.AddDays(1); @@ -120,7 +121,7 @@ namespace Persistence.IntegrationTests.Controllers public async Task GetLog_AfterSave_returns_success() { //arrange - var setpointKey = await Save(); + var setpointKey = await Add(); //act var response = await setpointClient.GetLog([setpointKey]); @@ -144,8 +145,8 @@ namespace Persistence.IntegrationTests.Controllers //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); - Assert.Equal(DateTimeOffset.MinValue, response.Content?.From); - Assert.Equal(DateTimeOffset.MaxValue, response.Content?.To); + Assert.Equal(DateTimeOffset.MinValue, response.Content!.From); + Assert.Equal(DateTimeOffset.MaxValue, response.Content!.To); } [Fact] @@ -153,7 +154,12 @@ namespace Persistence.IntegrationTests.Controllers { //arrange dbContext.CleanupDbSet(); - await Save(); + + await Add(); + + var dateBegin = DateTimeOffset.MinValue; + var take = 1; + var part = await setpointClient.GetPart(dateBegin, take, new CancellationToken()); //act var response = await setpointClient.GetDatesRangeAsync(new CancellationToken()); @@ -161,8 +167,17 @@ namespace Persistence.IntegrationTests.Controllers //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); - Assert.NotNull(response.Content?.From); - Assert.NotNull(response.Content?.To); + + var expectedValue = part.Content! + .FirstOrDefault()!.Created + .ToString("dd.MM.yyyy-HH:mm:ss"); + var actualValueFrom = response.Content.From + .ToString("dd.MM.yyyy-HH:mm:ss"); + Assert.Equal(expectedValue, actualValueFrom); + + var actualValueTo = response.Content.To + .ToString("dd.MM.yyyy-HH:mm:ss"); + Assert.Equal(expectedValue, actualValueTo); } [Fact] @@ -187,7 +202,7 @@ namespace Persistence.IntegrationTests.Controllers //arrange var dateBegin = DateTimeOffset.UtcNow; var take = 1; - await Save(); + await Add(); //act var response = await setpointClient.GetPart(dateBegin, take, new CancellationToken()); @@ -201,10 +216,10 @@ namespace Persistence.IntegrationTests.Controllers [Fact] public async Task Save_returns_success() { - await Save(); + await Add(); } - private async Task Save() + private async Task Add() { //arrange var setpointKey = Guid.NewGuid(); @@ -215,10 +230,10 @@ namespace Persistence.IntegrationTests.Controllers }; //act - var response = await setpointClient.Save(setpointKey, setpointValue); + var response = await setpointClient.Add(setpointKey, setpointValue); //assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(HttpStatusCode.Created, response.StatusCode); return setpointKey; } diff --git a/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs b/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs index ec4e40a..1f194ad 100644 --- a/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs @@ -97,7 +97,7 @@ namespace Persistence.IntegrationTests.Controllers }; //act - var response = await techMessagesClient.InsertRange(dtos, new CancellationToken()); + var response = await techMessagesClient.AddRange(dtos, new CancellationToken()); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); @@ -276,7 +276,7 @@ namespace Persistence.IntegrationTests.Controllers //act - var response = await techMessagesClient.InsertRange(dtos, new CancellationToken()); + var response = await techMessagesClient.AddRange(dtos, new CancellationToken()); //assert Assert.Equal(HttpStatusCode.Created, response.StatusCode); diff --git a/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs b/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs index 87efa43..08bb11e 100644 --- a/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TimeSeriesBaseControllerTest.cs @@ -30,7 +30,7 @@ public abstract class TimeSeriesBaseControllerTest : BaseIntegrat var expected = dto.Adapt(); //act - var response = await timeSeriesClient.InsertRange(new TDto[] { expected }); + var response = await timeSeriesClient.AddRange(new TDto[] { expected }); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); diff --git a/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs b/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs index aa33e1b..3fc7dff 100644 --- a/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs @@ -25,7 +25,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest IEnumerable testSets = Generate(10, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); // act - var response = await client.InsertRange(idDiscriminator, testSets); + var response = await client.AddRange(idDiscriminator, testSets); // assert Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode); @@ -39,7 +39,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest Guid idDiscriminator = Guid.NewGuid(); int count = 10; IEnumerable testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); // act var response = await client.Get(idDiscriminator, null, null, 0, int.MaxValue); @@ -58,7 +58,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest Guid idDiscriminator = Guid.NewGuid(); int count = 10; IEnumerable testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); string[] props = ["A"]; // act @@ -86,7 +86,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest var dateMin = DateTimeOffset.Now; var dateMax = DateTimeOffset.Now.AddSeconds(count); IEnumerable testSets = Generate(count, dateMin.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); var tail = testSets.OrderBy(t => t.Timestamp).Skip(count / 2).Take(int.MaxValue); var geDate = tail.First().Timestamp; var tolerance = TimeSpan.FromSeconds(1); @@ -111,7 +111,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest Guid idDiscriminator = Guid.NewGuid(); int count = 10; IEnumerable testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); var expectedCount = count / 2; // act @@ -133,7 +133,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest var expectedCount = 1; int count = 10 + expectedCount; IEnumerable testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); // act var response = await client.Get(idDiscriminator, null, null, count - expectedCount, count); @@ -152,7 +152,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest Guid idDiscriminator = Guid.NewGuid(); int count = 10; IEnumerable testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); var expectedCount = 8; // act @@ -174,7 +174,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest var dateMin = DateTimeOffset.Now; var dateMax = DateTimeOffset.Now.AddSeconds(count-1); IEnumerable testSets = Generate(count, dateMin.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); var tolerance = TimeSpan.FromSeconds(1); // act @@ -195,7 +195,7 @@ public class TimestampedSetControllerTest : BaseIntegrationTest Guid idDiscriminator = Guid.NewGuid(); int count = 144; IEnumerable testSets = Generate(count, DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(7))); - var insertResponse = await client.InsertRange(idDiscriminator, testSets); + var insertResponse = await client.AddRange(idDiscriminator, testSets); // act var response = await client.Count(idDiscriminator); diff --git a/Persistence.Repository/Repositories/SetpointRepository.cs b/Persistence.Repository/Repositories/SetpointRepository.cs index 8f0492c..f0e921f 100644 --- a/Persistence.Repository/Repositories/SetpointRepository.cs +++ b/Persistence.Repository/Repositories/SetpointRepository.cs @@ -47,7 +47,7 @@ namespace Persistence.Repository.Repositories { var query = GetQueryReadOnly(); var entities = await query - .Where(e => e.Created > dateBegin) + .Where(e => e.Created >= dateBegin) .Take(take) .ToArrayAsync(token); var dtos = entities diff --git a/Persistence.Repository/Repositories/TechMessagesRepository.cs b/Persistence.Repository/Repositories/TechMessagesRepository.cs index 04bab02..38d24e8 100644 --- a/Persistence.Repository/Repositories/TechMessagesRepository.cs +++ b/Persistence.Repository/Repositories/TechMessagesRepository.cs @@ -114,7 +114,7 @@ namespace Persistence.Repository.Repositories { var query = GetQueryReadOnly(); var entities = await query - .Where(e => e.Timestamp > dateBegin) + .Where(e => e.Timestamp >= dateBegin) .Take(take) .ToArrayAsync(token); var dtos = entities From 2228c841397a1532c492e7d52dcfba36938a82d4 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Wed, 4 Dec 2024 16:29:15 +0500 Subject: [PATCH 3/3] =?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); /// /// Получение списка уникальных названий систем АБ