0
0

Compare commits

...

4 Commits

Author SHA1 Message Date
fb0fcda84c Implement KeyedServices 2023-12-30 14:43:25 +03:00
72465f655f Update packages 2023-12-30 14:37:18 +03:00
c896d2aeb8 Update packages 2023-12-30 14:36:59 +03:00
cac0418499 Update packages 2023-12-30 14:36:36 +03:00
10 changed files with 78 additions and 32 deletions

View File

@ -1,4 +1,4 @@
namespace RhSolutions.QueryModifiers;
namespace RhSolutions.Api.Tests;
public sealed class BypassQueryModifier : IProductQueryModifier
{

View File

@ -1,7 +1,7 @@
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
namespace RhSolutions.QueryModifiers;
namespace RhSolutions.Api.Tests;
public class ProductQueryModifierFactory
{
@ -40,7 +40,7 @@ public class ProductQueryModifierFactory
case "Муфта соединительная":
return new Coupling();
case "Угольник RAUTITAN":
return new ElbowModifier();
return new Elbow();
case "Фиксатор поворота отопление":
return new BendFormerHeating();
case "Фиксатор поворота водоснабжение":

View File

@ -1,3 +1,5 @@
namespace RhSolutions.Api.Tests;
public abstract class ProductQueryModifierTests
{
protected ProductQueryModifierFactory _factory;
@ -10,7 +12,7 @@ public abstract class ProductQueryModifierTests
public void Execute(string productType, string query, string expected)
{
var modifier = _factory.GetModifier(productType);
Assert.True(modifier.TryQueryModify(query, out var actual));
Assert.That(modifier.TryQueryModify(query, out var actual), Is.True);
Assert.That(actual, Is.EqualTo(expected));
}
}

View File

@ -1,18 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

View File

@ -7,21 +7,25 @@ namespace RhSolutions.Api.Middleware;
public class QueryModifier
{
private RequestDelegate _next;
private IServiceProvider _provider;
private IProductQueryModifier? _modifier;
public QueryModifier(RequestDelegate nextDelegate)
public QueryModifier(RequestDelegate nextDelegate, IServiceProvider provider)
{
_next = nextDelegate;
_provider = provider;
}
public async Task Invoke(HttpContext context, IProductTypePredicter typePredicter, ProductQueryModifierFactory productQueryModifierFactory)
public async Task Invoke(HttpContext context, IProductTypePredicter typePredicter)
{
if (context.Request.Method == HttpMethods.Get
&& context.Request.Path == "/api/search")
{
string query = context.Request.Query["query"].ToString();
var productType = typePredicter.GetPredictedProductType(query);
var modifier = productQueryModifierFactory.GetModifier(productType!);
if (modifier.TryQueryModify(query, out var modified))
_modifier = _provider.GetRequiredKeyedService<IProductQueryModifier>(productType);
if (_modifier == null) return;
if (_modifier.TryQueryModify(query, out var modified))
{
QueryBuilder qb = new()
{

View File

@ -14,8 +14,8 @@ public class RhSolutionsContext : DbContext
builder.Entity<Product>()
.Property(e => e.ProductSku)
.HasConversion(v => v.ToString(), v => new ProductSku(v));
builder.Entity<Product>()
.Property(e => e.DeprecatedSkus)
.HasPostgresArrayConversion<ProductSku, string>(v => v.ToString(), v => new ProductSku(v));
// builder.Entity<Product>()
// .Property(e => e.DeprecatedSkus)
// .HasPostgresArrayConversion<ProductSku, string>(v => v.ToString(), v => new ProductSku(v));
}
}

View File

@ -3,14 +3,16 @@ using RhSolutions.Models;
using RhSolutions.Api.Services;
using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
var builder = WebApplication.CreateBuilder(args);
string dbHost = builder.Configuration["DB_HOST"],
dbPort = builder.Configuration["DB_PORT"],
dbName = builder.Configuration["DB_DATABASE"],
dbUser = builder.Configuration["DB_USER"],
dbPassword = builder.Configuration["DB_PASSWORD"];
string dbHost = builder.Configuration["DB_HOST"] ?? "localhost",
dbPort = builder.Configuration["DB_PORT"] ?? "5000",
dbName = builder.Configuration["DB_DATABASE"] ?? "rhsolutions",
dbUser = builder.Configuration["DB_USER"] ?? "chebser",
dbPassword = builder.Configuration["DB_PASSWORD"] ?? "Rehau-987";
string connectionString = builder.Configuration["ConnectionsStrings:RhSolutionsLocal"]
?? $"Host={dbHost};Port={dbPort};Database={dbName};Username={dbUser};Password={dbPassword}";
@ -24,10 +26,40 @@ builder.Services.AddDbContext<RhSolutionsContext>(opts =>
}
});
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
.AddScoped<IProductTypePredicter, ProductTypePredicter>()
.AddSingleton<ProductQueryModifierFactory>();
.AddScoped<IProductTypePredicter, ProductTypePredicter>();
builder.Services.AddControllers();
builder.Services.AddKeyedScoped<IProductQueryModifier, Sleeve>("Монтажная гильза")
.AddKeyedScoped<IProductQueryModifier, SupportingClip>("Желоб")
.AddKeyedScoped<IProductQueryModifier, TPiece>("Тройник RAUTITAN")
.AddKeyedScoped<IProductQueryModifier, ThreadTPieceExternal>("Тройник RAUTITAN резьбовой наружный")
.AddKeyedScoped<IProductQueryModifier, ThreadTPieceInternal>("Тройник RAUTITAN резьбовой внутренний")
.AddKeyedScoped<IProductQueryModifier, AdapterExternal>("Переходник на наружную резьбу")
.AddKeyedScoped<IProductQueryModifier, AdapterInternal>("Переходник на внутреннюю резьбу")
.AddKeyedScoped<IProductQueryModifier, AdapterScrewcap>("Переходник с накидной гайкой")
.AddKeyedScoped<IProductQueryModifier, ThreadElbowExternal>("Угольник с наружной резьбой")
.AddKeyedScoped<IProductQueryModifier, ThreadElbowInternal>("Угольник с внутренней резьбой")
.AddKeyedScoped<IProductQueryModifier, ThreadElbowWallExternal>("Угольник настенный наружный")
.AddKeyedScoped<IProductQueryModifier, ThreadElbowWallInternal>("Угольник настенный внутренний")
.AddKeyedScoped<IProductQueryModifier, ThreadElbowDoubleWallInternal>("Проточный настенный угольник")
.AddKeyedScoped<IProductQueryModifier, ScrewcapElbow>("Угольник с накидной гайкой")
.AddKeyedScoped<IProductQueryModifier, Coupling>("Муфта соединительная")
.AddKeyedScoped<IProductQueryModifier, Elbow>("Угольник RAUTITAN")
.AddKeyedScoped<IProductQueryModifier, BendFormerHeating>("Фиксатор поворота отопление")
.AddKeyedScoped<IProductQueryModifier, BendFormerSanitary>("Фиксатор поворота водоснабжение")
.AddKeyedScoped<IProductQueryModifier, ConnectionBend>("Трубка Г-образная")
.AddKeyedScoped<IProductQueryModifier, ConnectionTee>("Трубка Т-образная")
.AddKeyedScoped<IProductQueryModifier, EuroconeFlex>("Резьбозажимное flex")
.AddKeyedScoped<IProductQueryModifier, EuroconeStabil>("Резьбозажимное stabil")
.AddKeyedScoped<IProductQueryModifier, EuroconeAdapter>("Переходник на евроконус")
.AddKeyedScoped<IProductQueryModifier, EuroconeConnectionBend>("Резьбозажимное для трубки")
.AddKeyedScoped<IProductQueryModifier, Nippel>("Ниппель")
.AddKeyedScoped<IProductQueryModifier, DummyPlug>("Заглушка труб RAUTITAN")
.AddKeyedScoped<IProductQueryModifier, FlexPipe>("Flex")
.AddKeyedScoped<IProductQueryModifier, PinkPipe>("Pink")
.AddKeyedScoped<IProductQueryModifier, StabilPipe>("Stabil")
.AddKeyedScoped<IProductQueryModifier, BlackPipe>("Black");
var app = builder.Build();
app.MapControllers();

View File

@ -1,22 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>1c307973-55cf-4d5c-a4f8-1def6b58ee3c</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.100.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="ClosedXML" Version="0.102.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ML" Version="2.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="Microsoft.ML" Version="3.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Rhsolutions.ProductSku" Version="1.0.0" />
<PackageReference Include="Rhsolutions.ProductSku" Version="1.1.2" />
</ItemGroup>
<ItemGroup>

View File

@ -1,6 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ElbowModifier : DrinkingWaterHeatingFitting
public class Elbow : DrinkingWaterHeatingFitting
{
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>