From ae3e164df17aaf5564c30e3105c21c26de7990ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8F=20=D0=91=D0=B8=D0=B7=D1=8E=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Thu, 5 Dec 2024 11:30:07 +0500 Subject: [PATCH] Merge from dev --- .../Controllers/TechMessagesController.cs | 3 +- Persistence.API/DependencyInjection.cs | 24 ++--- .../Clients/ITechMessagesClient.cs | 3 +- .../PersistenceDbContext.cs | 19 ++-- .../Controllers/TechMessagesControllerTest.cs | 13 +-- .../Repositories/TechMessagesRepository.cs | 3 +- .../Repositories/ITechMessagesRepository.cs | 100 +++++++++--------- 7 files changed, 83 insertions(+), 82 deletions(-) diff --git a/Persistence.API/Controllers/TechMessagesController.cs b/Persistence.API/Controllers/TechMessagesController.cs index d2691c1..a7b0094 100644 --- a/Persistence.API/Controllers/TechMessagesController.cs +++ b/Persistence.API/Controllers/TechMessagesController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Persistence.Models; +using Persistence.Models.Requests; using Persistence.Repositories; namespace Persistence.API.Controllers; @@ -36,7 +37,7 @@ public class TechMessagesController : ControllerBase /// /// [HttpGet] - public async Task>> GetPage([FromQuery] RequestDto request, CancellationToken token) + public async Task>> GetPage([FromQuery] PaginationRequest request, CancellationToken token) { var result = await techMessagesRepository.GetPage(request, token); diff --git a/Persistence.API/DependencyInjection.cs b/Persistence.API/DependencyInjection.cs index 6170eeb..bf297a6 100644 --- a/Persistence.API/DependencyInjection.cs +++ b/Persistence.API/DependencyInjection.cs @@ -1,4 +1,3 @@ -using System.Text.Json.Nodes; using Mapster; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; @@ -8,18 +7,19 @@ using Persistence.Database.Entity; using Persistence.Models; using Persistence.Models.Configurations; using Swashbuckle.AspNetCore.SwaggerGen; +using System.Reflection; using System.Text.Json.Nodes; namespace Persistence.API; public static class DependencyInjection { - public static void MapsterSetup() - { - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .Ignore(dest => dest.System, dest => dest.SystemId); - } + public static void MapsterSetup() + { + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Ignore(dest => dest.System, dest => dest.SystemId); + } public static void AddSwagger(this IServiceCollection services, IConfiguration configuration) { services.AddSwaggerGen(c => @@ -48,11 +48,11 @@ public static class DependencyInjection c.AddKeycloackSecurity(configuration); else c.AddDefaultSecurity(configuration); - var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; - var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); - var includeControllerXmlComment = true; - c.IncludeXmlComments(xmlPath, includeControllerXmlComment); - }); + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + var includeControllerXmlComment = true; + c.IncludeXmlComments(xmlPath, includeControllerXmlComment); + }); } #region Authentication diff --git a/Persistence.Client/Clients/ITechMessagesClient.cs b/Persistence.Client/Clients/ITechMessagesClient.cs index 878c6cf..a9c80c1 100644 --- a/Persistence.Client/Clients/ITechMessagesClient.cs +++ b/Persistence.Client/Clients/ITechMessagesClient.cs @@ -1,4 +1,5 @@ using Persistence.Models; +using Persistence.Models.Requests; using Refit; namespace Persistence.Client.Clients @@ -11,7 +12,7 @@ namespace Persistence.Client.Clients private const string BaseRoute = "/api/techMessages"; [Get($"{BaseRoute}")] - Task>> GetPage([Query] RequestDto request, CancellationToken token); + Task>> GetPage([Query] PaginationRequest request, CancellationToken token); [Post($"{BaseRoute}")] Task> AddRange([Body] IEnumerable dtos, CancellationToken token); diff --git a/Persistence.Database.Postgres/PersistenceDbContext.cs b/Persistence.Database.Postgres/PersistenceDbContext.cs index 9d6e4cf..80a9e25 100644 --- a/Persistence.Database.Postgres/PersistenceDbContext.cs +++ b/Persistence.Database.Postgres/PersistenceDbContext.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using Npgsql; using Persistence.Database.Entity; -using System.Data.Common; namespace Persistence.Database.Model; public partial class PersistenceDbContext : DbContext @@ -9,16 +7,16 @@ public partial class PersistenceDbContext : DbContext public DbSet DataSaub => Set(); public DbSet ChangeLog => Set(); - public DbSet Setpoint => Set(); + public DbSet Setpoint => Set(); - public DbSet TechMessage => Set(); + public DbSet TechMessage => Set(); - public DbSet TimestampedSets => Set(); + public DbSet TimestampedSets => Set(); public PersistenceDbContext() : base() { - + } public PersistenceDbContext(DbContextOptions options) @@ -50,12 +48,11 @@ public partial class PersistenceDbContext : DbContext .WithMany() .HasForeignKey(t => t.SystemId) .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - } + .IsRequired(); + }); modelBuilder.Entity() - .Property(e => e.Value) - .HasJsonConversion(); + .Property(e => e.Value) + .HasJsonConversion(); } } diff --git a/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs b/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs index 1f194ad..291991f 100644 --- a/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/TechMessagesControllerTest.cs @@ -5,6 +5,7 @@ using Persistence.Client; using Persistence.Client.Clients; using Persistence.Database.Entity; using Persistence.Models; +using Persistence.Models.Requests; using Xunit; namespace Persistence.IntegrationTests.Controllers @@ -32,7 +33,7 @@ namespace Persistence.IntegrationTests.Controllers dbContext.CleanupDbSet(); dbContext.CleanupDbSet(); - var requestDto = new RequestDto() + var PaginationRequest = new PaginationRequest() { Skip = 1, Take = 2, @@ -40,14 +41,14 @@ namespace Persistence.IntegrationTests.Controllers }; //act - var response = await techMessagesClient.GetPage(requestDto, new CancellationToken()); + var response = await techMessagesClient.GetPage(PaginationRequest, new CancellationToken()); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); Assert.Empty(response.Content.Items); - Assert.Equal(requestDto.Skip, response.Content.Skip); - Assert.Equal(requestDto.Take, response.Content.Take); + Assert.Equal(PaginationRequest.Skip, response.Content.Skip); + Assert.Equal(PaginationRequest.Take, response.Content.Take); } [Fact] @@ -56,7 +57,7 @@ namespace Persistence.IntegrationTests.Controllers //arrange var dtos = await InsertRange(); var dtosCount = dtos.Count(); - var requestDto = new RequestDto() + var PaginationRequest = new PaginationRequest() { Skip = 0, Take = 2, @@ -64,7 +65,7 @@ namespace Persistence.IntegrationTests.Controllers }; //act - var response = await techMessagesClient.GetPage(requestDto, new CancellationToken()); + var response = await techMessagesClient.GetPage(PaginationRequest, new CancellationToken()); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); diff --git a/Persistence.Repository/Repositories/TechMessagesRepository.cs b/Persistence.Repository/Repositories/TechMessagesRepository.cs index c838619..d2efbe4 100644 --- a/Persistence.Repository/Repositories/TechMessagesRepository.cs +++ b/Persistence.Repository/Repositories/TechMessagesRepository.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Persistence.Database.Entity; using Persistence.Models; +using Persistence.Models.Requests; using Persistence.Repositories; using Persistence.Repository.Extensions; @@ -24,7 +25,7 @@ namespace Persistence.Repository.Repositories protected virtual IQueryable GetQueryReadOnly() => db.Set() .Include(e => e.System); - public async Task> GetPage(RequestDto request, CancellationToken token) + public async Task> GetPage(PaginationRequest request, CancellationToken token) { var query = GetQueryReadOnly(); var count = await query.CountAsync(token); diff --git a/Persistence/Repositories/ITechMessagesRepository.cs b/Persistence/Repositories/ITechMessagesRepository.cs index 92e8f70..ae92912 100644 --- a/Persistence/Repositories/ITechMessagesRepository.cs +++ b/Persistence/Repositories/ITechMessagesRepository.cs @@ -1,59 +1,59 @@ -using System.Threading.Tasks; -using Persistence.Models; +using Persistence.Models; +using Persistence.Models.Requests; namespace Persistence.Repositories { - /// - /// Интерфейс по работе с технологическими сообщениями - /// - public interface ITechMessagesRepository - { - /// - /// Получить страницу списка объектов - /// - /// - /// - /// - Task> GetPage(RequestDto request, CancellationToken token); + /// + /// Интерфейс по работе с технологическими сообщениями + /// + public interface ITechMessagesRepository + { + /// + /// Получить страницу списка объектов + /// + /// + /// + /// + Task> GetPage(PaginationRequest request, CancellationToken token); - /// - /// Добавление новых сообщений - /// - /// - /// - /// - Task AddRange(IEnumerable dtos, Guid userId, CancellationToken token); + /// + /// Добавление новых сообщений + /// + /// + /// + /// + Task AddRange(IEnumerable dtos, Guid userId, CancellationToken token); - /// - /// Получение списка уникальных названий систем АБ - /// - /// - /// - Task> GetSystems(CancellationToken token); + /// + /// Получение списка уникальных названий систем АБ + /// + /// + /// + Task> GetSystems(CancellationToken token); - /// - /// Получение количества сообщений по категориям и системам автобурения - /// - /// Id Категории важности - /// Система автобурения - /// - /// - Task> GetStatistics(IEnumerable autoDrillingSystem, IEnumerable categoryIds, CancellationToken token); + /// + /// Получение количества сообщений по категориям и системам автобурения + /// + /// Id Категории важности + /// Система автобурения + /// + /// + Task> GetStatistics(IEnumerable autoDrillingSystem, IEnumerable categoryIds, CancellationToken token); - /// - /// Получить порцию записей, начиная с заданной даты - /// - /// - /// - /// - /// - Task> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token); + /// + /// Получить порцию записей, начиная с заданной даты + /// + /// + /// + /// + /// + Task> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token); - /// - /// Получить диапазон дат, для которых есть данные в репозитории - /// - /// - /// - Task GetDatesRangeAsync(CancellationToken token); - } + /// + /// Получить диапазон дат, для которых есть данные в репозитории + /// + /// + /// + Task GetDatesRangeAsync(CancellationToken token); + } }