Compare commits
4 Commits
b91d8fbe99
...
fb0fcda84c
Author | SHA1 | Date | |
---|---|---|---|
fb0fcda84c | |||
72465f655f | |||
c896d2aeb8 | |||
cac0418499 |
@ -1,4 +1,4 @@
|
|||||||
namespace RhSolutions.QueryModifiers;
|
namespace RhSolutions.Api.Tests;
|
||||||
|
|
||||||
public sealed class BypassQueryModifier : IProductQueryModifier
|
public sealed class BypassQueryModifier : IProductQueryModifier
|
||||||
{
|
{
|
@ -1,7 +1,7 @@
|
|||||||
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||||
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||||
|
|
||||||
namespace RhSolutions.QueryModifiers;
|
namespace RhSolutions.Api.Tests;
|
||||||
|
|
||||||
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 ElbowModifier();
|
return new Elbow();
|
||||||
case "Фиксатор поворота отопление":
|
case "Фиксатор поворота отопление":
|
||||||
return new BendFormerHeating();
|
return new BendFormerHeating();
|
||||||
case "Фиксатор поворота водоснабжение":
|
case "Фиксатор поворота водоснабжение":
|
@ -1,3 +1,5 @@
|
|||||||
|
namespace RhSolutions.Api.Tests;
|
||||||
|
|
||||||
public abstract class ProductQueryModifierTests
|
public abstract class ProductQueryModifierTests
|
||||||
{
|
{
|
||||||
protected ProductQueryModifierFactory _factory;
|
protected ProductQueryModifierFactory _factory;
|
||||||
@ -10,7 +12,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.True(modifier.TryQueryModify(query, out var actual));
|
Assert.That(modifier.TryQueryModify(query, out var actual), Is.True);
|
||||||
Assert.That(actual, Is.EqualTo(expected));
|
Assert.That(actual, Is.EqualTo(expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,18 +1,24 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.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.1.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
<PackageReference Include="NUnit" Version="4.0.1" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||||
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
|
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
<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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -7,21 +7,25 @@ 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)
|
public QueryModifier(RequestDelegate nextDelegate, IServiceProvider provider)
|
||||||
{
|
{
|
||||||
_next = nextDelegate;
|
_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
|
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);
|
||||||
var modifier = productQueryModifierFactory.GetModifier(productType!);
|
_modifier = _provider.GetRequiredKeyedService<IProductQueryModifier>(productType);
|
||||||
if (modifier.TryQueryModify(query, out var modified))
|
if (_modifier == null) return;
|
||||||
|
if (_modifier.TryQueryModify(query, out var modified))
|
||||||
{
|
{
|
||||||
QueryBuilder qb = new()
|
QueryBuilder qb = new()
|
||||||
{
|
{
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,16 @@ 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"],
|
string dbHost = builder.Configuration["DB_HOST"] ?? "localhost",
|
||||||
dbPort = builder.Configuration["DB_PORT"],
|
dbPort = builder.Configuration["DB_PORT"] ?? "5000",
|
||||||
dbName = builder.Configuration["DB_DATABASE"],
|
dbName = builder.Configuration["DB_DATABASE"] ?? "rhsolutions",
|
||||||
dbUser = builder.Configuration["DB_USER"],
|
dbUser = builder.Configuration["DB_USER"] ?? "chebser",
|
||||||
dbPassword = builder.Configuration["DB_PASSWORD"];
|
dbPassword = builder.Configuration["DB_PASSWORD"] ?? "Rehau-987";
|
||||||
|
|
||||||
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}";
|
||||||
@ -24,10 +26,40 @@ 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();
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.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.100.0" />
|
<PackageReference Include="ClosedXML" Version="0.102.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
<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>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.ML" Version="2.0.1" />
|
<PackageReference Include="Microsoft.ML" Version="3.0.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
||||||
<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.0.0" />
|
<PackageReference Include="Rhsolutions.ProductSku" Version="1.1.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||||
|
|
||||||
public class ElbowModifier : DrinkingWaterHeatingFitting
|
public class Elbow : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";
|
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user