From 6e55d5b542f64496049e63dab3417eb74fb5ae9b Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 31 Jan 2024 11:15:21 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B3=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20/=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=B2=D0=BE=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8:=20=D0=B3=D1=80=D1=83=D0=BF?= =?UTF-8?q?=D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BE=D0=BA=20=D0=BF=D0=BE=20name=20=D0=B2=D0=BD=D1=82?= =?UTF-8?q?=D1=83=D1=80=D0=B8=20=20ValidationBadRequest=20+=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BA=D0=BE=D0=B4,=20=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=B9=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B8=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D0=B5=D1=86=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B=D0=B4=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/WellOperationRepository.cs | 12 ++++++------ AsbCloudWebApi/Extentions.cs | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 208e94ac..ea9a6975 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -383,12 +383,12 @@ public class WellOperationRepository : IWellOperationRepository new[] { nameof(wellOperationDtos) }); } - if (previousDateEnd > currentDateStart) - { - yield return new ValidationResult( - "Предыдущая операция не завершена", - new[] { nameof(wellOperationDtos) }); - } + //if (previousDateEnd > currentDateStart) + //{ + // yield return new ValidationResult( + // "Предыдущая операция не завершена", + // new[] { nameof(wellOperationDtos) }); + //} previous = current; } diff --git a/AsbCloudWebApi/Extentions.cs b/AsbCloudWebApi/Extentions.cs index 5659292c..7299fae5 100644 --- a/AsbCloudWebApi/Extentions.cs +++ b/AsbCloudWebApi/Extentions.cs @@ -70,8 +70,10 @@ namespace Microsoft.AspNetCore.Mvc public static BadRequestObjectResult ValidationBadRequest(this ControllerBase controller, IEnumerable validationResults) { var errors = validationResults - .SelectMany(e => e.MemberNames.Select(name=> new { name, e.ErrorMessage })) - .ToDictionary(e => e.name, e => new[] { e.ErrorMessage ?? string.Empty }); + .SelectMany(e => e.MemberNames.Select(name => new { name, e.ErrorMessage })) + .GroupBy(e => e.name) + .ToDictionary(e => e.Key, e => e.Select(el => el.ErrorMessage ?? string.Empty).ToArray()); + var problem = new ValidationProblemDetails(errors); return controller.BadRequest(problem); } From 514d4fe80a340d7f1bb6977c3b7f72bf95af9f08 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 31 Jan 2024 12:03:35 +0500 Subject: [PATCH 2/5] ChangeLogRepositoryAbstract Add Ordering --- .../Repository/ChangeLogRepositoryAbstract.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs b/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs index 84506a21..64208a8e 100644 --- a/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs +++ b/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs @@ -193,7 +193,8 @@ public abstract class ChangeLogRepositoryAbstract : ICh dates = dates.Select(date => date.ToOffset(offset)); var datesOnly = dates .Select(d => new DateOnly(d.Year, d.Month, d.Day)) - .Distinct(); + .Distinct() + .OrderBy(d => d); return datesOnly; } @@ -214,7 +215,11 @@ public abstract class ChangeLogRepositoryAbstract : ICh query = createdQuery.Union(editedQuery); } - var entities = await query.ToListAsync(token); + var entities = await query + .OrderBy(e => e.Creation) + .ThenBy(e => e.Obsolete) + .ThenBy(e => e.Id) + .ToListAsync(token); var dtos = entities.Select(e => Convert(e, offset)); return dtos; @@ -223,7 +228,11 @@ public abstract class ChangeLogRepositoryAbstract : ICh public async Task> Get(TRequest request, CancellationToken token) { var query = BuildQuery(request); - var entities = await query.ToArrayAsync(token); + var entities = await query + .OrderBy(e => e.Creation) + .ThenBy(e => e.Obsolete) + .ThenBy(e => e.Id) + .ToArrayAsync(token); TimeSpan offset = GetTimezoneOffset(request); var dtos = entities.Select(e => Convert(e, offset)); From 855b483f22d323622ed6b94c72315904bcfb4a8c Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 31 Jan 2024 13:53:07 +0500 Subject: [PATCH 3/5] fix SlipsStatControllerTest --- .../Controllers/SlipsStatControllerTest.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs index a31c5f19..908d5b95 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs @@ -2,6 +2,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Requests; using AsbCloudDb.Model; using AsbCloudWebApi.IntegrationTests.Clients; +using Microsoft.EntityFrameworkCore; using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers; @@ -10,7 +11,7 @@ public class SlipsStatControllerTest : BaseIntegrationTest { private static readonly Schedule schedule = new() { - Id = 1, + Id = 0, IdDriller = Data.Defaults.Drillers[0].Id, IdWell = Data.Defaults.Wells[0].Id, ShiftStart = new TimeOnly(8, 0, 0), @@ -21,7 +22,7 @@ public class SlipsStatControllerTest : BaseIntegrationTest private static readonly DetectedOperation detectedOperation = new() { - Id = 1, + Id = 0, IdTelemetry = Data.Defaults.Telemetries[0].Id, IdCategory = WellOperationCategory.IdSlipsTime, DateStart = new DateTimeOffset(new DateTime(2024, 1, 23, 15, 0, 0, 0, DateTimeKind.Utc)), @@ -34,7 +35,7 @@ public class SlipsStatControllerTest : BaseIntegrationTest private static readonly WellOperation factWellOperation = new() { - Id = 1, + Id = 0, IdWell = Data.Defaults.Wells[0].Id, IdWellSectionType = 1, IdCategory = WellOperationCategory.IdRotor, @@ -51,9 +52,18 @@ public class SlipsStatControllerTest : BaseIntegrationTest public SlipsStatControllerTest(WebAppFactoryFixture factory) : base(factory) { - dbContext.Schedule.Add(schedule); - dbContext.DetectedOperations.Add(detectedOperation); - dbContext.WellOperations.Add(factWellOperation); + var schedules = dbContext.Set(); + var detectedOperations = dbContext.Set(); + var wellOperations = dbContext.Set(); + + schedules.RemoveRange(schedules); + detectedOperations.RemoveRange(detectedOperations); + wellOperations.RemoveRange(wellOperations); + dbContext.SaveChanges(); + + schedules.Add(schedule); + detectedOperations.Add(detectedOperation); + wellOperations.Add(factWellOperation); dbContext.SaveChanges(); client = factory.GetAuthorizedHttpClient(); From 75a40c763cc12affb83f99cd17683c1ad236cb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 31 Jan 2024 14:43:17 +0500 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A3=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=B0=D0=BA?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BD=D0=B8=D0=BA=D0=B0=D1=8E=D1=89=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D0=B8=20iText7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/AsbCloudInfrastructure.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index c607d523..02400268 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -55,6 +55,7 @@ + From c59b402b137f0e2eeb78f2bf66dcdeb535ac15cc Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 1 Feb 2024 13:28:41 +0500 Subject: [PATCH 5/5] Fix TelemetryDataCache.GetOrDefault(...) --- AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs index 99983dd5..7a94d595 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs @@ -299,7 +299,7 @@ namespace AsbCloudInfrastructure.Services.SAUB if (request.LeDate.HasValue) { var leDate = request.LeDate.Value.ToRemoteDateTime(cacheItem.TimezoneHours); - data = data.Where(d => d.DateTime >= request.LeDate); + data = data.Where(d => d.DateTime <= request.LeDate); } if (request.Divider > 1)