0
0

Compare commits

..

No commits in common. "fb0fcda84cefc79a19d8cfcb784f78abc7b61ffb" and "b91d8fbe99ac56155e6b7547d2e4931832eeb9f4" have entirely different histories.

10 changed files with 32 additions and 78 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -3,16 +3,14 @@ using RhSolutions.Models;
using RhSolutions.Api.Services; using RhSolutions.Api.Services;
using RhSolutions.Api.Middleware; using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers; using RhSolutions.QueryModifiers;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
string dbHost = builder.Configuration["DB_HOST"] ?? "localhost", string dbHost = builder.Configuration["DB_HOST"],
dbPort = builder.Configuration["DB_PORT"] ?? "5000", dbPort = builder.Configuration["DB_PORT"],
dbName = builder.Configuration["DB_DATABASE"] ?? "rhsolutions", dbName = builder.Configuration["DB_DATABASE"],
dbUser = builder.Configuration["DB_USER"] ?? "chebser", dbUser = builder.Configuration["DB_USER"],
dbPassword = builder.Configuration["DB_PASSWORD"] ?? "Rehau-987"; dbPassword = builder.Configuration["DB_PASSWORD"];
string connectionString = builder.Configuration["ConnectionsStrings:RhSolutionsLocal"] string connectionString = builder.Configuration["ConnectionsStrings:RhSolutionsLocal"]
?? $"Host={dbHost};Port={dbPort};Database={dbName};Username={dbUser};Password={dbPassword}"; ?? $"Host={dbHost};Port={dbPort};Database={dbName};Username={dbUser};Password={dbPassword}";
@ -26,40 +24,10 @@ builder.Services.AddDbContext<RhSolutionsContext>(opts =>
} }
}); });
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>() builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
.AddScoped<IProductTypePredicter, ProductTypePredicter>(); .AddScoped<IProductTypePredicter, ProductTypePredicter>()
.AddSingleton<ProductQueryModifierFactory>();
builder.Services.AddControllers(); 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(); var app = builder.Build();
app.MapControllers(); app.MapControllers();

View File

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

View File

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

View File

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

View File

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

View File

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