Правки по результатам ревью
This commit is contained in:
parent
10aa5dd36f
commit
591ecf5377
@ -78,7 +78,7 @@ public class TechMessagesController : ControllerBase
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("range")]
|
[HttpGet("range")]
|
||||||
public async Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync(CancellationToken token)
|
public async Task<ActionResult<DatesRangeDto?>> GetDatesRangeAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await techMessagesRepository.GetDatesRangeAsync(token);
|
var result = await techMessagesRepository.GetDatesRangeAsync(token);
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ public abstract class BaseClient
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> ExecuteGetResponse<T>(Func<Task<IApiResponse<T>>> getMethod, CancellationToken token)
|
public async Task<T?> ExecuteGetResponse<T>(Func<Task<IApiResponse<T>>> getMethod, CancellationToken token)
|
||||||
{
|
{
|
||||||
var response = await getMethod.Invoke().WaitAsync(token);
|
var response = await getMethod.Invoke().WaitAsync(token);
|
||||||
|
|
||||||
if (response.IsSuccessful)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return response.Content;
|
return response.Content;
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ public abstract class BaseClient
|
|||||||
{
|
{
|
||||||
var response = await postMethod.Invoke().WaitAsync(token);
|
var response = await postMethod.Invoke().WaitAsync(token);
|
||||||
|
|
||||||
if (response.IsSuccessful)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ public abstract class BaseClient
|
|||||||
{
|
{
|
||||||
var response = await postMethod.Invoke().WaitAsync(token);
|
var response = await postMethod.Invoke().WaitAsync(token);
|
||||||
|
|
||||||
if (response.IsSuccessful)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return response.Content;
|
return response.Content;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class ChangeLogClient : BaseClient, IChangeLogClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitChangeLogClient.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, token), token);
|
async () => await refitChangeLogClient.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token)
|
public async Task<int> Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token)
|
||||||
|
@ -25,7 +25,7 @@ public class DataSourceSystemClient : BaseClient, IDataSourceSystemClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await dataSourceSystemClient.Get(token), token);
|
async () => await dataSourceSystemClient.Get(token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -21,7 +21,7 @@ public interface ITechMessagesClient : IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
|
Task<DatesRangeDto?> GetDatesRangeAsync(CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список технологических сообщений в виде страницы
|
/// Получить список технологических сообщений в виде страницы
|
||||||
|
@ -19,7 +19,7 @@ namespace Persistence.Client.Clients.Interfaces.Refit
|
|||||||
Task<IApiResponse<IEnumerable<DataSourceSystemDto>>> GetSystems(CancellationToken token);
|
Task<IApiResponse<IEnumerable<DataSourceSystemDto>>> GetSystems(CancellationToken token);
|
||||||
|
|
||||||
[Get($"{BaseRoute}/range")]
|
[Get($"{BaseRoute}/range")]
|
||||||
Task<IApiResponse<DatesRangeDto>> GetDatesRangeAsync(CancellationToken token);
|
Task<IApiResponse<DatesRangeDto?>> GetDatesRangeAsync(CancellationToken token);
|
||||||
|
|
||||||
[Get($"{BaseRoute}/part")]
|
[Get($"{BaseRoute}/part")]
|
||||||
Task<IApiResponse<IEnumerable<TechMessageDto>>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token);
|
Task<IApiResponse<IEnumerable<TechMessageDto>>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token);
|
||||||
|
@ -20,7 +20,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetCurrent(setpointKeys, token), token);
|
async () => await refitSetpointClient.GetCurrent(setpointKeys, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
||||||
@ -28,7 +28,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
public async Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
||||||
@ -36,7 +36,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
|
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
||||||
@ -44,7 +44,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetDatesRangeAsync(token), token);
|
async () => await refitSetpointClient.GetDatesRangeAsync(token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointLogDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
public async Task<IEnumerable<SetpointLogDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
||||||
@ -52,7 +52,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
|
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
|
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
|
||||||
|
@ -21,7 +21,7 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTechMessagesClient.GetPage(request, token), token);
|
async () => await refitTechMessagesClient.GetPage(request, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> AddRange(Guid systemId, IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
public async Task<int> AddRange(Guid systemId, IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
||||||
@ -37,10 +37,10 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTechMessagesClient.GetSystems(token), token);
|
async () => await refitTechMessagesClient.GetSystems(token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
public async Task<DatesRangeDto?> GetDatesRangeAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTechMessagesClient.GetDatesRangeAsync(token), token);
|
async () => await refitTechMessagesClient.GetDatesRangeAsync(token), token);
|
||||||
@ -53,7 +53,7 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTechMessagesClient.GetPart(dateBegin, take, token), token);
|
async () => await refitTechMessagesClient.GetPart(dateBegin, take, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<MessagesStatisticDto>> GetStatistics(IEnumerable<Guid> systemIds, IEnumerable<int> categoryIds, CancellationToken token)
|
public async Task<IEnumerable<MessagesStatisticDto>> GetStatistics(IEnumerable<Guid> systemIds, IEnumerable<int> categoryIds, CancellationToken token)
|
||||||
@ -61,7 +61,7 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTechMessagesClient.GetStatistics(systemIds, categoryIds, token), token);
|
async () => await refitTechMessagesClient.GetStatistics(systemIds, categoryIds, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -27,7 +27,7 @@ public class TimeSeriesClient<TDto> : BaseClient, ITimeSeriesClient<TDto> where
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await timeSeriesClient.Get(dateBegin, dateEnd, token), token);
|
async () => await timeSeriesClient.Get(dateBegin, dateEnd, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<TDto>> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
|
public async Task<IEnumerable<TDto>> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
|
||||||
@ -35,7 +35,7 @@ public class TimeSeriesClient<TDto> : BaseClient, ITimeSeriesClient<TDto> where
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await timeSeriesClient.GetResampledData(dateBegin, intervalSec, approxPointsCount, token), token);
|
async () => await timeSeriesClient.GetResampledData(dateBegin, intervalSec, approxPointsCount, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DatesRangeDto?> GetDatesRange(CancellationToken token)
|
public async Task<DatesRangeDto?> GetDatesRange(CancellationToken token)
|
||||||
|
@ -27,7 +27,7 @@ public class TimestampedSetClient : BaseClient, ITimestampedSetClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTimestampedSetClient.Get(idDiscriminator, geTimestamp, columnNames, skip, take, token), token);
|
async () => await refitTimestampedSetClient.Get(idDiscriminator, geTimestamp, columnNames, skip, take, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<TimestampedSetDto>> GetLast(Guid idDiscriminator, IEnumerable<string>? columnNames, int take, CancellationToken token)
|
public async Task<IEnumerable<TimestampedSetDto>> GetLast(Guid idDiscriminator, IEnumerable<string>? columnNames, int take, CancellationToken token)
|
||||||
@ -35,7 +35,7 @@ public class TimestampedSetClient : BaseClient, ITimestampedSetClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitTimestampedSetClient.GetLast(idDiscriminator, columnNames, take, token), token);
|
async () => await refitTimestampedSetClient.GetLast(idDiscriminator, columnNames, take, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> Count(Guid idDiscriminator, CancellationToken token)
|
public async Task<int> Count(Guid idDiscriminator, CancellationToken token)
|
||||||
|
@ -27,7 +27,7 @@ public class WitsDataClient : BaseClient, IWitsDataClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitWitsDataClient.GetDatesRangeAsync(discriminatorId, token), token);
|
async () => await refitWitsDataClient.GetDatesRangeAsync(discriminatorId, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WitsDataDto>> GetPart(Guid discriminatorId, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default)
|
public async Task<IEnumerable<WitsDataDto>> GetPart(Guid discriminatorId, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default)
|
||||||
@ -35,7 +35,7 @@ public class WitsDataClient : BaseClient, IWitsDataClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitWitsDataClient.GetPart(discriminatorId, dateBegin, take, token), token);
|
async () => await refitWitsDataClient.GetPart(discriminatorId, dateBegin, take, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WitsDataDto>> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token)
|
public async Task<IEnumerable<WitsDataDto>> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token)
|
||||||
@ -43,7 +43,7 @@ public class WitsDataClient : BaseClient, IWitsDataClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitWitsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token), token);
|
async () => await refitWitsDataClient.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token), token);
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -180,20 +180,18 @@ namespace Persistence.IntegrationTests.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetDatesRange_returns_success()
|
public async Task GetDatesRange_returns_NoContent()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
memoryCache.Remove(SystemCacheKey);
|
memoryCache.Remove(SystemCacheKey);
|
||||||
dbContext.CleanupDbSet<TechMessage>();
|
dbContext.CleanupDbSet<TechMessage>();
|
||||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.NotNull(response);
|
Assert.Null(response);
|
||||||
Assert.Equal(DateTimeOffset.MinValue, response?.From);
|
|
||||||
Assert.Equal(DateTimeOffset.MaxValue, response?.To);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -31,6 +31,6 @@ public class DataSourceSystemCachedRepository : DataSourceSystemRepository
|
|||||||
return dtos;
|
return dtos;
|
||||||
});
|
});
|
||||||
|
|
||||||
return systems ?? [];
|
return systems!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ namespace Persistence.Repository.Repositories
|
|||||||
{
|
{
|
||||||
System = group.FirstOrDefault()!.System.Name,
|
System = group.FirstOrDefault()!.System.Name,
|
||||||
Categories = group
|
Categories = group
|
||||||
.Where(g => categoryIds.Count() == 0 || categoryIds.Contains(g.CategoryId))
|
.Where(g => !categoryIds.Any() || categoryIds.Contains(g.CategoryId))
|
||||||
})
|
})
|
||||||
.ToArrayAsync(token);
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ namespace Persistence.Repository.Repositories
|
|||||||
return systems!;
|
return systems!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
public async Task<DatesRangeDto?> GetDatesRangeAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = GetQueryReadOnly()
|
var query = GetQueryReadOnly()
|
||||||
.GroupBy(e => 1)
|
.GroupBy(e => 1)
|
||||||
@ -130,7 +130,11 @@ namespace Persistence.Repository.Repositories
|
|||||||
Min = group.Min(e => e.Timestamp),
|
Min = group.Min(e => e.Timestamp),
|
||||||
Max = group.Max(e => e.Timestamp),
|
Max = group.Max(e => e.Timestamp),
|
||||||
});
|
});
|
||||||
|
|
||||||
var values = await query.FirstOrDefaultAsync(token);
|
var values = await query.FirstOrDefaultAsync(token);
|
||||||
|
if (values == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
var result = new DatesRangeDto()
|
var result = new DatesRangeDto()
|
||||||
{
|
{
|
||||||
From = values?.Min ?? DateTimeOffset.MinValue,
|
From = values?.Min ?? DateTimeOffset.MinValue,
|
||||||
|
@ -54,6 +54,6 @@ namespace Persistence.Repositories
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
|
Task<DatesRangeDto?> GetDatesRangeAsync(CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user