2024-12-09 14:45:35 +05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Client.Clients.Base;
|
|
|
|
|
using DD.Persistence.Client.Clients.Interfaces;
|
|
|
|
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
|
|
|
|
using DD.Persistence.Models;
|
|
|
|
|
using DD.Persistence.Models.Requests;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.Client.Clients;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
|
|
|
|
public class TechMessagesClient : BaseClient, ITechMessagesClient
|
|
|
|
|
{
|
|
|
|
|
private readonly IRefitTechMessagesClient refitTechMessagesClient;
|
|
|
|
|
|
2024-12-27 13:35:18 +05:00
|
|
|
|
public TechMessagesClient(IRefitClientFactory<IRefitTechMessagesClient> refitTechMessagesClientFactory, ILogger<TechMessagesClient> logger) : base(logger)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
2024-12-27 13:35:18 +05:00
|
|
|
|
this.refitTechMessagesClient = refitTechMessagesClientFactory.Create();
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 13:55:01 +05:00
|
|
|
|
public async Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
|
async () => await refitTechMessagesClient.GetPage(request, token), token);
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 11:47:52 +05:00
|
|
|
|
public async Task<int> AddRange(Guid systemId, IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
|
|
|
|
var result = await ExecutePostResponse(
|
2024-12-12 11:47:52 +05:00
|
|
|
|
async () => await refitTechMessagesClient.AddRange(systemId, dtos, token), token);
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 17:05:47 +05:00
|
|
|
|
public async Task<IEnumerable<DataSourceSystemDto>> GetSystems(CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
|
async () => await refitTechMessagesClient.GetSystems(token), token);
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
public async Task<DatesRangeDto?> GetDatesRangeAsync(CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
|
async () => await refitTechMessagesClient.GetDatesRangeAsync(token), token);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TechMessageDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
|
async () => await refitTechMessagesClient.GetPart(dateBegin, take, token), token);
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 11:47:52 +05:00
|
|
|
|
public async Task<IEnumerable<MessagesStatisticDto>> GetStatistics(IEnumerable<Guid> systemIds, IEnumerable<int> categoryIds, CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-12 11:47:52 +05:00
|
|
|
|
async () => await refitTechMessagesClient.GetStatistics(systemIds, categoryIds, token), token);
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
2024-12-10 13:55:01 +05:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
refitTechMessagesClient.Dispose();
|
2024-12-13 15:30:11 +05:00
|
|
|
|
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|