Merge from dev

This commit is contained in:
Оля Бизюкова 2024-12-05 11:30:07 +05:00
parent c66b0bbc2f
commit ae3e164df1
7 changed files with 83 additions and 82 deletions

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Persistence.Models; using Persistence.Models;
using Persistence.Models.Requests;
using Persistence.Repositories; using Persistence.Repositories;
namespace Persistence.API.Controllers; namespace Persistence.API.Controllers;
@ -36,7 +37,7 @@ public class TechMessagesController : ControllerBase
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<ActionResult<PaginationContainer<TechMessageDto>>> GetPage([FromQuery] RequestDto request, CancellationToken token) public async Task<ActionResult<PaginationContainer<TechMessageDto>>> GetPage([FromQuery] PaginationRequest request, CancellationToken token)
{ {
var result = await techMessagesRepository.GetPage(request, token); var result = await techMessagesRepository.GetPage(request, token);

View File

@ -1,4 +1,3 @@
using System.Text.Json.Nodes;
using Mapster; using Mapster;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
@ -8,18 +7,19 @@ using Persistence.Database.Entity;
using Persistence.Models; using Persistence.Models;
using Persistence.Models.Configurations; using Persistence.Models.Configurations;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using System.Reflection;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
namespace Persistence.API; namespace Persistence.API;
public static class DependencyInjection public static class DependencyInjection
{ {
public static void MapsterSetup() public static void MapsterSetup()
{ {
TypeAdapterConfig.GlobalSettings.Default.Config TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<TechMessageDto, TechMessage>() .ForType<TechMessageDto, TechMessage>()
.Ignore(dest => dest.System, dest => dest.SystemId); .Ignore(dest => dest.System, dest => dest.SystemId);
} }
public static void AddSwagger(this IServiceCollection services, IConfiguration configuration) public static void AddSwagger(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddSwaggerGen(c => services.AddSwaggerGen(c =>
@ -48,11 +48,11 @@ public static class DependencyInjection
c.AddKeycloackSecurity(configuration); c.AddKeycloackSecurity(configuration);
else c.AddDefaultSecurity(configuration); else c.AddDefaultSecurity(configuration);
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
var includeControllerXmlComment = true; var includeControllerXmlComment = true;
c.IncludeXmlComments(xmlPath, includeControllerXmlComment); c.IncludeXmlComments(xmlPath, includeControllerXmlComment);
}); });
} }
#region Authentication #region Authentication

View File

@ -1,4 +1,5 @@
using Persistence.Models; using Persistence.Models;
using Persistence.Models.Requests;
using Refit; using Refit;
namespace Persistence.Client.Clients namespace Persistence.Client.Clients
@ -11,7 +12,7 @@ namespace Persistence.Client.Clients
private const string BaseRoute = "/api/techMessages"; private const string BaseRoute = "/api/techMessages";
[Get($"{BaseRoute}")] [Get($"{BaseRoute}")]
Task<IApiResponse<PaginationContainer<TechMessageDto>>> GetPage([Query] RequestDto request, CancellationToken token); Task<IApiResponse<PaginationContainer<TechMessageDto>>> GetPage([Query] PaginationRequest request, CancellationToken token);
[Post($"{BaseRoute}")] [Post($"{BaseRoute}")]
Task<IApiResponse<int>> AddRange([Body] IEnumerable<TechMessageDto> dtos, CancellationToken token); Task<IApiResponse<int>> AddRange([Body] IEnumerable<TechMessageDto> dtos, CancellationToken token);

View File

@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Npgsql;
using Persistence.Database.Entity; using Persistence.Database.Entity;
using System.Data.Common;
namespace Persistence.Database.Model; namespace Persistence.Database.Model;
public partial class PersistenceDbContext : DbContext public partial class PersistenceDbContext : DbContext
@ -9,16 +7,16 @@ public partial class PersistenceDbContext : DbContext
public DbSet<DataSaub> DataSaub => Set<DataSaub>(); public DbSet<DataSaub> DataSaub => Set<DataSaub>();
public DbSet<ChangeLog> ChangeLog => Set<ChangeLog>(); public DbSet<ChangeLog> ChangeLog => Set<ChangeLog>();
public DbSet<Setpoint> Setpoint => Set<Setpoint>(); public DbSet<Setpoint> Setpoint => Set<Setpoint>();
public DbSet<TechMessage> TechMessage => Set<TechMessage>(); public DbSet<TechMessage> TechMessage => Set<TechMessage>();
public DbSet<TimestampedSet> TimestampedSets => Set<TimestampedSet>(); public DbSet<TimestampedSet> TimestampedSets => Set<TimestampedSet>();
public PersistenceDbContext() public PersistenceDbContext()
: base() : base()
{ {
} }
public PersistenceDbContext(DbContextOptions<PersistenceDbContext> options) public PersistenceDbContext(DbContextOptions<PersistenceDbContext> options)
@ -50,12 +48,11 @@ public partial class PersistenceDbContext : DbContext
.WithMany() .WithMany()
.HasForeignKey(t => t.SystemId) .HasForeignKey(t => t.SystemId)
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
}
modelBuilder.Entity<ChangeLog>() modelBuilder.Entity<ChangeLog>()
.Property(e => e.Value) .Property(e => e.Value)
.HasJsonConversion(); .HasJsonConversion();
} }
} }

View File

@ -5,6 +5,7 @@ using Persistence.Client;
using Persistence.Client.Clients; using Persistence.Client.Clients;
using Persistence.Database.Entity; using Persistence.Database.Entity;
using Persistence.Models; using Persistence.Models;
using Persistence.Models.Requests;
using Xunit; using Xunit;
namespace Persistence.IntegrationTests.Controllers namespace Persistence.IntegrationTests.Controllers
@ -32,7 +33,7 @@ namespace Persistence.IntegrationTests.Controllers
dbContext.CleanupDbSet<TechMessage>(); dbContext.CleanupDbSet<TechMessage>();
dbContext.CleanupDbSet<Database.Entity.DrillingSystem>(); dbContext.CleanupDbSet<Database.Entity.DrillingSystem>();
var requestDto = new RequestDto() var PaginationRequest = new PaginationRequest()
{ {
Skip = 1, Skip = 1,
Take = 2, Take = 2,
@ -40,14 +41,14 @@ namespace Persistence.IntegrationTests.Controllers
}; };
//act //act
var response = await techMessagesClient.GetPage(requestDto, new CancellationToken()); var response = await techMessagesClient.GetPage(PaginationRequest, new CancellationToken());
//assert //assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content); Assert.NotNull(response.Content);
Assert.Empty(response.Content.Items); Assert.Empty(response.Content.Items);
Assert.Equal(requestDto.Skip, response.Content.Skip); Assert.Equal(PaginationRequest.Skip, response.Content.Skip);
Assert.Equal(requestDto.Take, response.Content.Take); Assert.Equal(PaginationRequest.Take, response.Content.Take);
} }
[Fact] [Fact]
@ -56,7 +57,7 @@ namespace Persistence.IntegrationTests.Controllers
//arrange //arrange
var dtos = await InsertRange(); var dtos = await InsertRange();
var dtosCount = dtos.Count(); var dtosCount = dtos.Count();
var requestDto = new RequestDto() var PaginationRequest = new PaginationRequest()
{ {
Skip = 0, Skip = 0,
Take = 2, Take = 2,
@ -64,7 +65,7 @@ namespace Persistence.IntegrationTests.Controllers
}; };
//act //act
var response = await techMessagesClient.GetPage(requestDto, new CancellationToken()); var response = await techMessagesClient.GetPage(PaginationRequest, new CancellationToken());
//assert //assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Persistence.Database.Entity; using Persistence.Database.Entity;
using Persistence.Models; using Persistence.Models;
using Persistence.Models.Requests;
using Persistence.Repositories; using Persistence.Repositories;
using Persistence.Repository.Extensions; using Persistence.Repository.Extensions;
@ -24,7 +25,7 @@ namespace Persistence.Repository.Repositories
protected virtual IQueryable<TechMessage> GetQueryReadOnly() => db.Set<TechMessage>() protected virtual IQueryable<TechMessage> GetQueryReadOnly() => db.Set<TechMessage>()
.Include(e => e.System); .Include(e => e.System);
public async Task<PaginationContainer<TechMessageDto>> GetPage(RequestDto request, CancellationToken token) public async Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token)
{ {
var query = GetQueryReadOnly(); var query = GetQueryReadOnly();
var count = await query.CountAsync(token); var count = await query.CountAsync(token);

View File

@ -1,59 +1,59 @@
using System.Threading.Tasks; using Persistence.Models;
using Persistence.Models; using Persistence.Models.Requests;
namespace Persistence.Repositories namespace Persistence.Repositories
{ {
/// <summary> /// <summary>
/// Интерфейс по работе с технологическими сообщениями /// Интерфейс по работе с технологическими сообщениями
/// </summary> /// </summary>
public interface ITechMessagesRepository public interface ITechMessagesRepository
{ {
/// <summary> /// <summary>
/// Получить страницу списка объектов /// Получить страницу списка объектов
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<PaginationContainer<TechMessageDto>> GetPage(RequestDto request, CancellationToken token); Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token);
/// <summary> /// <summary>
/// Добавление новых сообщений /// Добавление новых сообщений
/// </summary> /// </summary>
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> AddRange(IEnumerable<TechMessageDto> dtos, Guid userId, CancellationToken token); Task<int> AddRange(IEnumerable<TechMessageDto> dtos, Guid userId, CancellationToken token);
/// <summary> /// <summary>
/// Получение списка уникальных названий систем АБ /// Получение списка уникальных названий систем АБ
/// </summary> /// </summary>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<string>> GetSystems(CancellationToken token); Task<IEnumerable<string>> GetSystems(CancellationToken token);
/// <summary> /// <summary>
/// Получение количества сообщений по категориям и системам автобурения /// Получение количества сообщений по категориям и системам автобурения
/// </summary> /// </summary>
/// <param name="categoryId">Id Категории важности</param> /// <param name="categoryId">Id Категории важности</param>
/// <param name="autoDrillingSystem">Система автобурения</param> /// <param name="autoDrillingSystem">Система автобурения</param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<MessagesStatisticDto>> GetStatistics(IEnumerable<string> autoDrillingSystem, IEnumerable<int> categoryIds, CancellationToken token); Task<IEnumerable<MessagesStatisticDto>> GetStatistics(IEnumerable<string> autoDrillingSystem, IEnumerable<int> categoryIds, CancellationToken token);
/// <summary> /// <summary>
/// Получить порцию записей, начиная с заданной даты /// Получить порцию записей, начиная с заданной даты
/// </summary> /// </summary>
/// <param name="dateBegin"></param> /// <param name="dateBegin"></param>
/// <param name="take"></param> /// <param name="take"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TechMessageDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token); Task<IEnumerable<TechMessageDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token);
/// <summary> /// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории /// Получить диапазон дат, для которых есть данные в репозитории
/// </summary> /// </summary>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token); Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
} }
} }