From 591ecf53774287728c6d9e562a3cbdef9a9a1b10 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Fri, 13 Dec 2024 17:30:35 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=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 --- .../Controllers/TechMessagesController.cs | 2 +- Persistence.Client/Clients/Base/BaseClient.cs | 8 ++++---- Persistence.Client/Clients/ChangeLogClient.cs | 2 +- .../Clients/DataSourceSystemClient.cs | 2 +- .../Clients/Interfaces/ITechMessagesClient.cs | 2 +- .../Interfaces/Refit/IRefitTechMessagesClient.cs | 2 +- Persistence.Client/Clients/SetpointClient.cs | 10 +++++----- Persistence.Client/Clients/TechMessagesClient.cs | 10 +++++----- Persistence.Client/Clients/TimeSeriesClient.cs | 4 ++-- Persistence.Client/Clients/TimestampedSetClient.cs | 4 ++-- Persistence.Client/Clients/WitsDataClient.cs | 6 +++--- .../Controllers/TechMessagesControllerTest.cs | 14 ++++++-------- .../DataSourceSystemCachedRepository.cs | 2 +- .../Repositories/TechMessagesRepository.cs | 8 ++++++-- .../Repositories/ITechMessagesRepository.cs | 2 +- 15 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Persistence.API/Controllers/TechMessagesController.cs b/Persistence.API/Controllers/TechMessagesController.cs index 5945208..50481a0 100644 --- a/Persistence.API/Controllers/TechMessagesController.cs +++ b/Persistence.API/Controllers/TechMessagesController.cs @@ -78,7 +78,7 @@ public class TechMessagesController : ControllerBase /// /// [HttpGet("range")] - public async Task> GetDatesRangeAsync(CancellationToken token) + public async Task> GetDatesRangeAsync(CancellationToken token) { var result = await techMessagesRepository.GetDatesRangeAsync(token); diff --git a/Persistence.Client/Clients/Base/BaseClient.cs b/Persistence.Client/Clients/Base/BaseClient.cs index 2332cbd..c29cf14 100644 --- a/Persistence.Client/Clients/Base/BaseClient.cs +++ b/Persistence.Client/Clients/Base/BaseClient.cs @@ -12,11 +12,11 @@ public abstract class BaseClient this.logger = logger; } - public async Task ExecuteGetResponse(Func>> getMethod, CancellationToken token) + public async Task ExecuteGetResponse(Func>> getMethod, CancellationToken token) { var response = await getMethod.Invoke().WaitAsync(token); - if (response.IsSuccessful) + if (response.IsSuccessStatusCode) { return response.Content; } @@ -32,7 +32,7 @@ public abstract class BaseClient { var response = await postMethod.Invoke().WaitAsync(token); - if (response.IsSuccessful) + if (response.IsSuccessStatusCode) { return; } @@ -48,7 +48,7 @@ public abstract class BaseClient { var response = await postMethod.Invoke().WaitAsync(token); - if (response.IsSuccessful) + if (response.IsSuccessStatusCode) { return response.Content; } diff --git a/Persistence.Client/Clients/ChangeLogClient.cs b/Persistence.Client/Clients/ChangeLogClient.cs index bd3e49e..78c71a7 100644 --- a/Persistence.Client/Clients/ChangeLogClient.cs +++ b/Persistence.Client/Clients/ChangeLogClient.cs @@ -36,7 +36,7 @@ public class ChangeLogClient : BaseClient, IChangeLogClient var result = await ExecuteGetResponse( async () => await refitChangeLogClient.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, token), token); - return result; + return result!; } public async Task Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token) diff --git a/Persistence.Client/Clients/DataSourceSystemClient.cs b/Persistence.Client/Clients/DataSourceSystemClient.cs index f68f0c3..25ec605 100644 --- a/Persistence.Client/Clients/DataSourceSystemClient.cs +++ b/Persistence.Client/Clients/DataSourceSystemClient.cs @@ -25,7 +25,7 @@ public class DataSourceSystemClient : BaseClient, IDataSourceSystemClient var result = await ExecuteGetResponse( async () => await dataSourceSystemClient.Get(token), token); - return result; + return result!; } public void Dispose() diff --git a/Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs b/Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs index 2d6abe9..5545dad 100644 --- a/Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs +++ b/Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs @@ -21,7 +21,7 @@ public interface ITechMessagesClient : IDisposable /// /// /// - Task GetDatesRangeAsync(CancellationToken token); + Task GetDatesRangeAsync(CancellationToken token); /// /// Получить список технологических сообщений в виде страницы diff --git a/Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs b/Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs index b1b90b2..3e4cd10 100644 --- a/Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs +++ b/Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs @@ -19,7 +19,7 @@ namespace Persistence.Client.Clients.Interfaces.Refit Task>> GetSystems(CancellationToken token); [Get($"{BaseRoute}/range")] - Task> GetDatesRangeAsync(CancellationToken token); + Task> GetDatesRangeAsync(CancellationToken token); [Get($"{BaseRoute}/part")] Task>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token); diff --git a/Persistence.Client/Clients/SetpointClient.cs b/Persistence.Client/Clients/SetpointClient.cs index 3dba7a0..ea6d767 100644 --- a/Persistence.Client/Clients/SetpointClient.cs +++ b/Persistence.Client/Clients/SetpointClient.cs @@ -20,7 +20,7 @@ public class SetpointClient : BaseClient, ISetpointClient var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetCurrent(setpointKeys, token), token); - return result; + return result!; } public async Task> GetHistory(IEnumerable setpointKeys, DateTimeOffset historyMoment, CancellationToken token) @@ -28,7 +28,7 @@ public class SetpointClient : BaseClient, ISetpointClient var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token); - return result; + return result!; } public async Task>> GetLog(IEnumerable setpointKeys, CancellationToken token) @@ -36,7 +36,7 @@ public class SetpointClient : BaseClient, ISetpointClient var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetLog(setpointKeys, token), token); - return result; + return result!; } public async Task GetDatesRangeAsync(CancellationToken token) @@ -44,7 +44,7 @@ public class SetpointClient : BaseClient, ISetpointClient var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetDatesRangeAsync(token), token); - return result; + return result!; } public async Task> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token) @@ -52,7 +52,7 @@ public class SetpointClient : BaseClient, ISetpointClient var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetPart(dateBegin, take, token), token); - return result; + return result!; } public async Task Add(Guid setpointKey, object newValue, CancellationToken token) diff --git a/Persistence.Client/Clients/TechMessagesClient.cs b/Persistence.Client/Clients/TechMessagesClient.cs index 5c90359..f69c110 100644 --- a/Persistence.Client/Clients/TechMessagesClient.cs +++ b/Persistence.Client/Clients/TechMessagesClient.cs @@ -21,7 +21,7 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient var result = await ExecuteGetResponse( async () => await refitTechMessagesClient.GetPage(request, token), token); - return result; + return result!; } public async Task AddRange(Guid systemId, IEnumerable dtos, CancellationToken token) @@ -37,10 +37,10 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient var result = await ExecuteGetResponse( async () => await refitTechMessagesClient.GetSystems(token), token); - return result; + return result!; } - public async Task GetDatesRangeAsync(CancellationToken token) + public async Task GetDatesRangeAsync(CancellationToken token) { var result = await ExecuteGetResponse( async () => await refitTechMessagesClient.GetDatesRangeAsync(token), token); @@ -53,7 +53,7 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient var result = await ExecuteGetResponse( async () => await refitTechMessagesClient.GetPart(dateBegin, take, token), token); - return result; + return result!; } public async Task> GetStatistics(IEnumerable systemIds, IEnumerable categoryIds, CancellationToken token) @@ -61,7 +61,7 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient var result = await ExecuteGetResponse( async () => await refitTechMessagesClient.GetStatistics(systemIds, categoryIds, token), token); - return result; + return result!; } public void Dispose() diff --git a/Persistence.Client/Clients/TimeSeriesClient.cs b/Persistence.Client/Clients/TimeSeriesClient.cs index 416ae84..72b8ed8 100644 --- a/Persistence.Client/Clients/TimeSeriesClient.cs +++ b/Persistence.Client/Clients/TimeSeriesClient.cs @@ -27,7 +27,7 @@ public class TimeSeriesClient : BaseClient, ITimeSeriesClient where var result = await ExecuteGetResponse( async () => await timeSeriesClient.Get(dateBegin, dateEnd, token), token); - return result; + return result!; } public async Task> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default) @@ -35,7 +35,7 @@ public class TimeSeriesClient : BaseClient, ITimeSeriesClient where var result = await ExecuteGetResponse( async () => await timeSeriesClient.GetResampledData(dateBegin, intervalSec, approxPointsCount, token), token); - return result; + return result!; } public async Task GetDatesRange(CancellationToken token) diff --git a/Persistence.Client/Clients/TimestampedSetClient.cs b/Persistence.Client/Clients/TimestampedSetClient.cs index e82abee..3009488 100644 --- a/Persistence.Client/Clients/TimestampedSetClient.cs +++ b/Persistence.Client/Clients/TimestampedSetClient.cs @@ -27,7 +27,7 @@ public class TimestampedSetClient : BaseClient, ITimestampedSetClient var result = await ExecuteGetResponse( async () => await refitTimestampedSetClient.Get(idDiscriminator, geTimestamp, columnNames, skip, take, token), token); - return result; + return result!; } public async Task> GetLast(Guid idDiscriminator, IEnumerable? columnNames, int take, CancellationToken token) @@ -35,7 +35,7 @@ public class TimestampedSetClient : BaseClient, ITimestampedSetClient var result = await ExecuteGetResponse( async () => await refitTimestampedSetClient.GetLast(idDiscriminator, columnNames, take, token), token); - return result; + return result!; } public async Task Count(Guid idDiscriminator, CancellationToken token) diff --git a/Persistence.Client/Clients/WitsDataClient.cs b/Persistence.Client/Clients/WitsDataClient.cs index acd8bbf..73e5873 100644 --- a/Persistence.Client/Clients/WitsDataClient.cs +++ b/Persistence.Client/Clients/WitsDataClient.cs @@ -27,7 +27,7 @@ public class WitsDataClient : BaseClient, IWitsDataClient var result = await ExecuteGetResponse( async () => await refitWitsDataClient.GetDatesRangeAsync(discriminatorId, token), token); - return result; + return result!; } public async Task> GetPart(Guid discriminatorId, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default) @@ -35,7 +35,7 @@ public class WitsDataClient : BaseClient, IWitsDataClient var result = await ExecuteGetResponse( async () => await refitWitsDataClient.GetPart(discriminatorId, dateBegin, take, token), token); - return result; + return result!; } public async Task> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token) @@ -43,7 +43,7 @@ public class WitsDataClient : BaseClient, IWitsDataClient var result = await ExecuteGetResponse( async () => await refitWitsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token), token); - return result; + return result!; } public void Dispose() diff --git a/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs b/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs index b01f9e9..c51804a 100644 --- a/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs @@ -180,20 +180,18 @@ namespace Persistence.IntegrationTests.Controllers } [Fact] - public async Task GetDatesRange_returns_success() + public async Task GetDatesRange_returns_NoContent() { //arrange memoryCache.Remove(SystemCacheKey); dbContext.CleanupDbSet(); dbContext.CleanupDbSet(); - //act - var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None); - - //assert - Assert.NotNull(response); - Assert.Equal(DateTimeOffset.MinValue, response?.From); - Assert.Equal(DateTimeOffset.MaxValue, response?.To); + //act + var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None); + + //assert + Assert.Null(response); } [Fact] diff --git a/Persistence.Repository/Repositories/DataSourceSystemCachedRepository.cs b/Persistence.Repository/Repositories/DataSourceSystemCachedRepository.cs index b95790e..5869992 100644 --- a/Persistence.Repository/Repositories/DataSourceSystemCachedRepository.cs +++ b/Persistence.Repository/Repositories/DataSourceSystemCachedRepository.cs @@ -31,6 +31,6 @@ public class DataSourceSystemCachedRepository : DataSourceSystemRepository return dtos; }); - return systems ?? []; + return systems!; } } diff --git a/Persistence.Repository/Repositories/TechMessagesRepository.cs b/Persistence.Repository/Repositories/TechMessagesRepository.cs index a2394ee..74aff0a 100644 --- a/Persistence.Repository/Repositories/TechMessagesRepository.cs +++ b/Persistence.Repository/Repositories/TechMessagesRepository.cs @@ -58,7 +58,7 @@ namespace Persistence.Repository.Repositories { System = group.FirstOrDefault()!.System.Name, Categories = group - .Where(g => categoryIds.Count() == 0 || categoryIds.Contains(g.CategoryId)) + .Where(g => !categoryIds.Any() || categoryIds.Contains(g.CategoryId)) }) .ToArrayAsync(token); @@ -121,7 +121,7 @@ namespace Persistence.Repository.Repositories return systems!; } - public async Task GetDatesRangeAsync(CancellationToken token) + public async Task GetDatesRangeAsync(CancellationToken token) { var query = GetQueryReadOnly() .GroupBy(e => 1) @@ -130,7 +130,11 @@ namespace Persistence.Repository.Repositories Min = group.Min(e => e.Timestamp), Max = group.Max(e => e.Timestamp), }); + var values = await query.FirstOrDefaultAsync(token); + if (values == null) + return null; + var result = new DatesRangeDto() { From = values?.Min ?? DateTimeOffset.MinValue, diff --git a/Persistence/Repositories/ITechMessagesRepository.cs b/Persistence/Repositories/ITechMessagesRepository.cs index 11c48fc..ebb7563 100644 --- a/Persistence/Repositories/ITechMessagesRepository.cs +++ b/Persistence/Repositories/ITechMessagesRepository.cs @@ -54,6 +54,6 @@ namespace Persistence.Repositories /// /// /// - Task GetDatesRangeAsync(CancellationToken token); + Task GetDatesRangeAsync(CancellationToken token); } }