diff --git a/Persistence.Client/Clients/ITimestampedSetClient.cs b/Persistence.Client/Clients/ITimestampedSetClient.cs index 96e2500..37b62be 100644 --- a/Persistence.Client/Clients/ITimestampedSetClient.cs +++ b/Persistence.Client/Clients/ITimestampedSetClient.cs @@ -1,7 +1,7 @@ using Persistence.Models; using Refit; -namespace Persistence.IntegrationTests.Clients; +namespace Persistence.Client.Clients; public interface ITimestampedSetClient { private const string baseUrl = "/api/TimestampedSet/{idDiscriminator}"; @@ -10,7 +10,7 @@ public interface ITimestampedSetClient Task> InsertRange(Guid idDiscriminator, IEnumerable sets); [Get(baseUrl)] - Task>> Get(Guid idDiscriminator, [Query]DateTimeOffset? geTimestamp, [Query]IEnumerable? props, int skip, int take); + Task>> Get(Guid idDiscriminator, [Query] DateTimeOffset? geTimestamp, [Query] IEnumerable? props, int skip, int take); [Get($"{baseUrl}/last")] Task>> GetLast(Guid idDiscriminator, [Query] IEnumerable? props, int take); diff --git a/Persistence.Database.Postgres/PersistenceDbContext.cs b/Persistence.Database.Postgres/PersistenceDbContext.cs index 053df12..a0cae6a 100644 --- a/Persistence.Database.Postgres/PersistenceDbContext.cs +++ b/Persistence.Database.Postgres/PersistenceDbContext.cs @@ -4,7 +4,7 @@ using Persistence.Database.Entity; using System.Data.Common; namespace Persistence.Database.Model; -public partial class PersistenceDbContext : DbContext, IPersistenceDbContext +public partial class PersistenceDbContext : DbContext { public DbSet DataSaub => Set(); diff --git a/Persistence.Database/IPersistenceDbContext.cs b/Persistence.Database/IPersistenceDbContext.cs deleted file mode 100644 index d23656e..0000000 --- a/Persistence.Database/IPersistenceDbContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Persistence.Database.Entity; -using Persistence.Database.Model; -using System.Diagnostics.CodeAnalysis; - -namespace Persistence.Database; -public interface IPersistenceDbContext : IDisposable -{ - DbSet DataSaub { get; } - DbSet TimestampedSets { get; } - DbSet Set<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.Interfaces)] TEntity>() where TEntity : class; - Task SaveChangesAsync(CancellationToken cancellationToken); -} diff --git a/Persistence.Database/Model/IPersistenceDbContext.cs b/Persistence.Database/Model/IPersistenceDbContext.cs deleted file mode 100644 index 2c1aebb..0000000 --- a/Persistence.Database/Model/IPersistenceDbContext.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using System; -using System.Collections.Generic; -using System.Diagnostics.Metrics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Persistence.Database.Model; -public interface IPersistenceDbContext : IDisposable -{ - DbSet DataSaub { get; } - DbSet Setpoint { get; } - DatabaseFacade Database { get; } - Task SaveChangesAsync(CancellationToken cancellationToken); -} diff --git a/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs b/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs index 12ebb94..aa33e1b 100644 --- a/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TimestampedSetControllerTest.cs @@ -1,5 +1,6 @@ -using Microsoft.AspNetCore.Mvc; -using Persistence.IntegrationTests.Clients; +using Microsoft.Extensions.DependencyInjection; +using Persistence.Client; +using Persistence.Client.Clients; using Persistence.Models; using Xunit; @@ -10,8 +11,10 @@ public class TimestampedSetControllerTest : BaseIntegrationTest public TimestampedSetControllerTest(WebAppFactoryFixture factory) : base(factory) { + var persistenceClientFactory = scope.ServiceProvider + .GetRequiredService(); - client = factory.GetAuthorizedHttpClient(string.Empty).Result; + client = persistenceClientFactory.GetClient(); } [Fact] diff --git a/Persistence.IntegrationTests/WebAppFactoryFixture.cs b/Persistence.IntegrationTests/WebAppFactoryFixture.cs index 1d99a2a..7b12362 100644 --- a/Persistence.IntegrationTests/WebAppFactoryFixture.cs +++ b/Persistence.IntegrationTests/WebAppFactoryFixture.cs @@ -43,9 +43,6 @@ public class WebAppFactoryFixture : WebApplicationFactory services.AddSingleton(); var serviceProvider = services.BuildServiceProvider(); - services.AddScoped(provider => provider.GetRequiredService()); - - var serviceProvider = services.BuildServiceProvider(); using var scope = serviceProvider.CreateScope(); var scopedServices = scope.ServiceProvider; diff --git a/Persistence.Repository/Repositories/TimestampedSetRepository.cs b/Persistence.Repository/Repositories/TimestampedSetRepository.cs index a190d71..ab6e1a8 100644 --- a/Persistence.Repository/Repositories/TimestampedSetRepository.cs +++ b/Persistence.Repository/Repositories/TimestampedSetRepository.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Persistence.Database; using Persistence.Database.Entity; using Persistence.Models; using Persistence.Repositories; @@ -14,9 +13,9 @@ namespace Persistence.Repository.Repositories; /// public class TimestampedSetRepository : ITimestampedSetRepository { - private readonly IPersistenceDbContext db; + private readonly DbContext db; - public TimestampedSetRepository(IPersistenceDbContext db) + public TimestampedSetRepository(DbContext db) { this.db = db; } @@ -37,6 +36,11 @@ public class TimestampedSetRepository : ITimestampedSetRepository if (geTimestamp.HasValue) query = ApplyGeTimestamp(query, geTimestamp.Value); + query = query + .OrderBy(item => item.Timestamp) + .Skip(skip) + .Take(take); + var data = await Materialize(query, token); if (props is not null && props.Any()) diff --git a/Persistence/Repositories/ITimestampedSetRepository.cs b/Persistence/Repositories/ITimestampedSetRepository.cs index 2966a82..980e47c 100644 --- a/Persistence/Repositories/ITimestampedSetRepository.cs +++ b/Persistence/Repositories/ITimestampedSetRepository.cs @@ -21,7 +21,7 @@ public interface ITimestampedSetRepository /// /// Получение данных с фильтрацией. Значение фильтра null - отключен /// - /// Идентификатор набора + /// Дискриминатор (идентификатор) набора /// Фильтр позднее даты /// Фильтр свойств набора. Можно запросить только некоторые свойства из набора /// @@ -41,8 +41,8 @@ public interface ITimestampedSetRepository /// /// Получить последние данные /// - /// - /// + /// Дискриминатор (идентификатор) набора + /// Фильтр свойств набора. Можно запросить только некоторые свойства из набора /// /// /// @@ -51,7 +51,7 @@ public interface ITimestampedSetRepository /// /// Добавление новых данных /// - /// + /// Дискриминатор (идентификатор) набора /// /// ///