0
0

Compare commits

...

3 Commits

32 changed files with 501 additions and 424 deletions

View File

@ -7,7 +7,8 @@ RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:6.0 FROM mcr.microsoft.com/dotnet/aspnet:6.0
EXPOSE 5000 EXPOSE 5000
EXPOSE 43000
WORKDIR /app WORKDIR /app
COPY --from=build /app/out . COPY --from=build /app/out .
ENV ASPNETCORE_ENVIRONMENT Production ENV ASPNETCORE_ENVIRONMENT Production
ENTRYPOINT [ "dotnet", "RhSolutions.Api.dll", "--urls=http://0.0.0.0:5000" ] ENTRYPOINT [ "dotnet", "RhSolutions.Api.dll" ]

View File

@ -1,6 +1,3 @@
using System.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
public abstract class ProductQueryModifierTests public abstract class ProductQueryModifierTests
{ {
protected ProductQueryModifierFactory _factory; protected ProductQueryModifierFactory _factory;
@ -10,17 +7,10 @@ public abstract class ProductQueryModifierTests
{ {
_factory = new ProductQueryModifierFactory(); _factory = new ProductQueryModifierFactory();
} }
public void Execute(string productType, string query, string modified) public void Execute(string productType, string query, string expected)
{ {
Dictionary<string, StringValues> queryPair = new()
{
["query"] = new StringValues(query)
};
QueryCollection collection = new(queryPair);
var modifier = _factory.GetModifier(productType); var modifier = _factory.GetModifier(productType);
Assert.True(modifier.TryQueryModify(query, out var actual));
Assert.True(modifier.TryQueryModify(collection, out var actual)); Assert.That(actual, Is.EqualTo(expected));
string? result = HttpUtility.ParseQueryString(actual.ToString())["query"];
Assert.That(result, Is.EqualTo(modified));
} }
} }

View File

@ -1,4 +1,5 @@
using RhSolutions.Api.Services; using Microsoft.AspNetCore.Http.Extensions;
using RhSolutions.Api.Services;
using RhSolutions.QueryModifiers; using RhSolutions.QueryModifiers;
namespace RhSolutions.Api.Middleware; namespace RhSolutions.Api.Middleware;
@ -20,9 +21,13 @@ public class QueryModifier
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!); var modifier = productQueryModifierFactory.GetModifier(productType!);
if (modifier.TryQueryModify(context.Request.Query, out var newQuery)) if (modifier.TryQueryModify(query, out var modified))
{ {
context.Request.QueryString = newQuery; QueryBuilder qb = new()
{
{"query", modified}
};
context.Request.QueryString = qb.ToQueryString();
} }
} }
await _next(context); await _next(context);

View File

@ -4,7 +4,7 @@ using RhSolutions.Api.Services;
using RhSolutions.Api.Middleware; using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers; using RhSolutions.QueryModifiers;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder();
string dbHost = builder.Configuration["DB_HOST"], string dbHost = builder.Configuration["DB_HOST"],
dbPort = builder.Configuration["DB_PORT"], dbPort = builder.Configuration["DB_PORT"],
@ -23,17 +23,18 @@ builder.Services.AddDbContext<RhSolutionsContext>(opts =>
opts.EnableSensitiveDataLogging(true); opts.EnableSensitiveDataLogging(true);
} }
}); });
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>() builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
.AddScoped<IProductTypePredicter, ProductTypePredicter>() .AddScoped<IProductTypePredicter, ProductTypePredicter>()
.AddSingleton<ProductQueryModifierFactory>(); .AddSingleton<ProductQueryModifierFactory>()
.AddGrpc();
builder.Services.AddControllers(); builder.Services.AddControllers();
var app = builder.Build(); var app = builder.Build();
app.MapControllers(); app.MapControllers();
app.MapGrpcService<SearchService>();
app.UseMiddleware<QueryModifier>(); app.UseMiddleware<QueryModifier>();
var context = app.Services.CreateScope().ServiceProvider
.GetRequiredService<RhSolutionsContext>();
app.Run(); app.Run();

View File

@ -4,7 +4,7 @@
"anonymousAuthentication": true, "anonymousAuthentication": true,
"launchBrowser": false, "launchBrowser": false,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:5000", "applicationUrl": "http://localhost:5000;http://localhost:43000",
"sslPort": 0 "sslPort": 0
} }
}, },
@ -13,7 +13,7 @@
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": false, "launchBrowser": false,
"applicationUrl": "http://localhost:5000", "applicationUrl": "http://localhost:5000;http://localhost:43000",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

View File

@ -0,0 +1,15 @@
syntax = "proto3";
service ProductSearch {
rpc GetProduct (ProductRequest) returns (ProductReply);
}
message ProductRequest {
string query = 1;
}
message ProductReply {
string id = 1;
string name = 2;
double price = 3;
}

View File

@ -9,6 +9,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="ClosedXML" Version="0.100.0" /> <PackageReference Include="ClosedXML" Version="0.100.0" />
<PackageReference Include="Grpc.AspnetCore" Version="2.58.0" />
<PackageReference Include="Grpc.Tools" Version="2.59.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@ -29,4 +34,9 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\product.proto" GrpcServices="Server" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,48 @@
using Grpc.Core;
using RhSolutions.Models;
using Microsoft.EntityFrameworkCore;
using RhSolutions.QueryModifiers;
namespace RhSolutions.Api.Services;
public class SearchService : ProductSearch.ProductSearchBase
{
private RhSolutionsContext _dbContext;
private IProductTypePredicter _typePredicter;
private ProductQueryModifierFactory _productQueryModifierFactory;
public SearchService(RhSolutionsContext dbContext, IProductTypePredicter typePredicter, ProductQueryModifierFactory productQueryModifierFactory)
{
_dbContext = dbContext;
_typePredicter = typePredicter;
_productQueryModifierFactory = productQueryModifierFactory;
}
public override async Task<ProductReply?> GetProduct(ProductRequest request, ServerCallContext context)
{
var productType = _typePredicter.GetPredictedProductType(request.Query);
var modifier = _productQueryModifierFactory.GetModifier(productType!);
string query = request.Query;
if (modifier.TryQueryModify(query, out var modified))
{
query = modified;
}
var product = await _dbContext.Products
.Where(p => EF.Functions.ToTsVector(
"russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines) }))
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
.OrderByDescending(p => p.IsOnWarehouse)
.FirstOrDefaultAsync();
if (product != null)
{
return new ProductReply()
{
Id = product.Id,
Name = product.Name,
Price = (double)product.Price
};
}
return null;
}
}

View File

@ -6,5 +6,17 @@
"Microsoft.EntityFrameworkCore": "Information" "Microsoft.EntityFrameworkCore": "Information"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:5000",
"Protocols": "Http1AndHttp2"
},
"gRPC": {
"Url": "http://0.0.0.0:43000",
"Protocols": "Http2"
}
}
}
} }

View File

@ -1,12 +1,10 @@
using Microsoft.AspNetCore.Http; namespace RhSolutions.QueryModifiers;
namespace RhSolutions.QueryModifiers;
public sealed class BypassQueryModifier : IProductQueryModifier public sealed class BypassQueryModifier : IProductQueryModifier
{ {
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) public bool TryQueryModify(string query, out string queryModified)
{ {
queryString = QueryString.Empty; queryModified = string.Empty;
return false; return false;
} }
} }

View File

@ -4,18 +4,20 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public abstract class Adapter : DrinkingWaterHeatingFitting public abstract class Adapter : DrinkingWaterHeatingFitting
{ {
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
Match diameter = _diameter.Match(query); output = string.Empty;
Match diameter = _diameter.Match(input);
if (!diameter.Success) if (!diameter.Success)
{ {
return null; return false;
} }
Match thread = _thread.Match(query); Match thread = _thread.Match(input);
if (!thread.Success) if (!thread.Success)
{ {
return null; return false;
} }
return $"{_title} {diameter.Groups["Diameter"]} {thread.Groups["Thread"]}"; output = $"{_title} {diameter.Groups["Diameter"]} {thread.Groups["Thread"]}";
return true;
} }
} }

View File

@ -3,20 +3,22 @@
public class BendFormerHeating : DrinkingWaterHeatingFitting public class BendFormerHeating : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Фиксатор поворота"; protected override string _title => "Фиксатор поворота";
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (!diameterMatch.Success) if (!diameterMatch.Success)
{ {
return null; return false;
} }
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
if (diameter == "16") if (diameter == "16")
{ {
diameter += "/17"; diameter += "/17";
} }
var angleMatch = _angle.Match(query); var angleMatch = _angle.Match(input);
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90"; string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
return $"{_title} {diameter}/{angle}°"; output = $"{_title} {diameter}/{angle}°";
return true;
} }
} }

View File

@ -3,16 +3,19 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class BendFormerSanitary : DrinkingWaterHeatingFitting public class BendFormerSanitary : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Фиксатор поворота с кольцами"; protected override string _title => "Фиксатор поворота с кольцами";
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (!diameterMatch.Success) if (!diameterMatch.Success)
{ {
return null; return false;
} }
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
var angleMatch = _angle.Match(query); var angleMatch = _angle.Match(input);
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90"; string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
return $"{_title} {angle}° {diameter}"; output = $"{_title} {angle}° {diameter}";
return true;
} }
} }

View File

@ -9,16 +9,18 @@ public class ConnectionBend : DrinkingWaterHeatingFitting
new(@"([\b\D]|^)?(?<Diameter>16|20|25)(\D+|.*15.*)(?<Length>\b\d{3,4})([\b\D]|$)"); new(@"([\b\D]|^)?(?<Diameter>16|20|25)(\D+|.*15.*)(?<Length>\b\d{3,4})([\b\D]|$)");
protected override string _title => "Трубка Г-образная"; protected override string _title => "Трубка Г-образная";
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
var match = _pattern.Match(query); output = string.Empty;
var match = _pattern.Match(input);
if (!match.Success) if (!match.Success)
{ {
return null; return false;
} }
string diameter = match.Groups["Diameter"].Value; string diameter = match.Groups["Diameter"].Value;
int length = int.Parse(match.Groups["Length"].Value); int length = int.Parse(match.Groups["Length"].Value);
int nearest = lengths.OrderBy(x => Math.Abs(x - length)).First(); int nearest = lengths.OrderBy(x => Math.Abs(x - length)).First();
return $"{_title} {diameter}/{nearest}"; output = $"{_title} {diameter}/{nearest}";
return true;
} }
} }

View File

@ -3,12 +3,14 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class Coupling : DrinkingWaterHeatingFitting public class Coupling : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Муфта соединительная"; protected override string _title => "Муфта соединительная";
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
var diametersMatches = _diameter.Matches(query); output = string.Empty;
var diametersMatches = _diameter.Matches(input);
if (diametersMatches.Count == 0) if (diametersMatches.Count == 0)
{ {
return null; return false;
} }
var diameters = diametersMatches.Select(x => x.Groups["Diameter"].Value) var diameters = diametersMatches.Select(x => x.Groups["Diameter"].Value)
.Take(2) .Take(2)
@ -16,11 +18,12 @@ public class Coupling : DrinkingWaterHeatingFitting
.ToArray(); .ToArray();
if (diameters.Length == 1 || diameters[0] == diameters[1]) if (diameters.Length == 1 || diameters[0] == diameters[1])
{ {
return $"{_title} равнопроходная {diameters[0]}"; output = $"{_title} равнопроходная {diameters[0]}";
} }
else else
{ {
return $"{_title} переходная {diameters[0]}-{diameters[1]}"; output = $"{_title} переходная {diameters[0]}-{diameters[1]}";
} }
return true;
} }
} }

View File

@ -1,6 +1,4 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
@ -15,34 +13,18 @@ public abstract class DrinkingWaterHeatingFitting : IProductQueryModifier
protected virtual string _title { get; } = string.Empty; protected virtual string _title { get; } = string.Empty;
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) public virtual bool TryQueryModify(string input, out string output)
{ {
queryString = QueryString.Empty; var match = _diameter.Match(input);
string query = collection["query"].ToString();
if (string.IsNullOrEmpty(query))
{
return false;
}
string? result = BuildRhSolutionsName(query);
if (result != null)
{
QueryBuilder qb = new()
{
{ "query", result }
};
queryString = qb.ToQueryString();
return true;
}
return false;
}
protected virtual string? BuildRhSolutionsName(string query)
{
var match = _diameter.Match(query);
if (match.Success) if (match.Success)
{ {
return $"{_title} {match.Groups["Diameter"]}"; output = $"{_title} {match.Groups["Diameter"]}";
return true;
}
else
{
output = string.Empty;
return false;
} }
return null;
} }
} }

View File

@ -3,16 +3,19 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ElbowModifier : DrinkingWaterHeatingFitting public class ElbowModifier : DrinkingWaterHeatingFitting
{ {
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM"; protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (!diameterMatch.Success) if (!diameterMatch.Success)
{ {
return null; return false;
} }
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
var angleMatch = _angle.Match(query); var angleMatch = _angle.Match(input);
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90"; string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
return $"{_title} {angle} {diameter}"; output = $"{_title} {angle} {diameter}";
return true;
} }
} }

View File

@ -4,18 +4,19 @@ public abstract class Eurocone : DrinkingWaterHeatingFitting
{ {
protected virtual Dictionary<string, string> _titles { get; } = new(); protected virtual Dictionary<string, string> _titles { get; } = new();
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (diameterMatch.Success) if (diameterMatch.Success)
{ {
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
if (_titles.TryGetValue(diameter, out string? title)) if (_titles.TryGetValue(diameter, out string? title))
{ {
return title; output = title;
} return true;
else return null; }
} }
return null; return false;
} }
} }

View File

@ -3,14 +3,17 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class EuroconeAdapter : DrinkingWaterHeatingFitting public class EuroconeAdapter : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Переходник на евроконус"; protected override string _title => "Переходник на евроконус";
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (diameterMatch.Success) if (diameterMatch.Success)
{ {
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
return $"{_title} {diameter}-G 3/4"; output = $"{_title} {diameter}-G 3/4";
return true;
} }
return null; return false;
} }
} }

View File

@ -2,8 +2,9 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class EuroconeConnectionBend : DrinkingWaterHeatingFitting public class EuroconeConnectionBend : DrinkingWaterHeatingFitting
{ {
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
return "Резьбозажимное соединение для металлической трубки G 3/4 -15"; output = "Резьбозажимное соединение для металлической трубки G 3/4 -15";
return true;
} }
} }

View File

@ -2,8 +2,9 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class Nippel : DrinkingWaterHeatingFitting public class Nippel : DrinkingWaterHeatingFitting
{ {
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
return "К-т двух резьбозажим. нипелей с нар.резьбой 1/2х3/4"; output = "К-т двух резьбозажим. нипелей с нар.резьбой 1/2х3/4";
return true;
} }
} }

View File

@ -4,9 +4,10 @@ public class SupportingClip : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Фиксирующий желоб для ПЭ-трубы"; protected override string _title => "Фиксирующий желоб для ПЭ-трубы";
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (diameterMatch.Success) if (diameterMatch.Success)
{ {
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
@ -14,8 +15,9 @@ public class SupportingClip : DrinkingWaterHeatingFitting
{ {
diameter += "/17"; diameter += "/17";
} }
return $"{_title} {diameter}"; output = $"{_title} {diameter}";
return true;
} }
return null; return false;
} }
} }

View File

@ -4,22 +4,24 @@ public class TPiece : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Тройник RAUTITAN -PLATINUM"; protected override string _title => "Тройник RAUTITAN -PLATINUM";
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
var diameters = _diameter.Matches(query) output = string.Empty;
var diameters = _diameter.Matches(input)
.Select(match => match.Groups["Diameter"].Value) .Select(match => match.Groups["Diameter"].Value)
.ToArray(); .ToArray();
if (diameters.Length == 1) if (diameters.Length == 1)
{ {
return $"{_title} {diameters[0]}-{diameters[0]}-{diameters[0]}"; output = $"{_title} {diameters[0]}-{diameters[0]}-{diameters[0]}";
} }
else if (diameters.Length >= 3) else if (diameters.Length >= 3)
{ {
return $"{_title} {diameters[0]}-{diameters[1]}-{diameters[2]}"; output = $"{_title} {diameters[0]}-{diameters[1]}-{diameters[2]}";
} }
else else
{ {
return null; return false;
} }
return true;
} }
} }

View File

@ -7,23 +7,25 @@ public class ThreadElbowDoubleWallInternal : DrinkingWaterHeatingFitting
protected override string _title => "Проточный настенный угольник"; protected override string _title => "Проточный настенный угольник";
private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])"); private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])");
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatches = _diameter.Matches(query); output = string.Empty;
var diameterMatches = _diameter.Matches(input);
if (diameterMatches.Count == 0) if (diameterMatches.Count == 0)
{ {
return null; return false;
} }
var threadMatch = _thread.Match(query); var threadMatch = _thread.Match(input);
if (!threadMatch.Success) if (!threadMatch.Success)
{ {
return null; return false;
} }
var typeMatch = _type.Match(query); var typeMatch = _type.Match(input);
string[] diameters = diameterMatches.Select(x => x.Groups["Diameter"].Value).ToArray(); string[] diameters = diameterMatches.Select(x => x.Groups["Diameter"].Value).ToArray();
string thread = threadMatch.Groups["Thread"].Value; string thread = threadMatch.Groups["Thread"].Value;
string type = typeMatch.Success ? "длинный" : "короткий"; string type = typeMatch.Success ? "длинный" : "короткий";
return $"{_title} {diameters[0]}/{(diameters.Length > 1 ? diameters[1] : diameters[0])}-Rp {thread} {type}"; output = $"{_title} {diameters[0]}/{(diameters.Length > 1 ? diameters[1] : diameters[0])}-Rp {thread} {type}";
return true;
} }
} }

View File

@ -3,20 +3,23 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ThreadElbowWallExternal : DrinkingWaterHeatingFitting public class ThreadElbowWallExternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Угольник настенный с наружной резьбой"; protected override string _title => "Угольник настенный с наружной резьбой";
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (!diameterMatch.Success) if (!diameterMatch.Success)
{ {
return null; return false;
} }
var threadMatch = _thread.Match(query); var threadMatch = _thread.Match(input);
if (!threadMatch.Success) if (!threadMatch.Success)
{ {
return null; return false;
} }
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
string thread = threadMatch.Groups["Thread"].Value; string thread = threadMatch.Groups["Thread"].Value;
return $"{_title} {diameter}-R {thread}"; output = $"{_title} {diameter}-R {thread}";
return true;
} }
} }

View File

@ -6,21 +6,24 @@ public class ThreadElbowWallInternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Угольник настенный внутр. резьба"; protected override string _title => "Угольник настенный внутр. резьба";
private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])"); private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])");
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
var diameterMatch = _diameter.Match(query); output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (!diameterMatch.Success) if (!diameterMatch.Success)
{ {
return null; return false;
} }
var threadMatch = _thread.Match(query); var threadMatch = _thread.Match(input);
if (!threadMatch.Success) if (!threadMatch.Success)
{ {
return null; return false;
} }
var typeMatch = _type.Match(query); var typeMatch = _type.Match(input);
string diameter = diameterMatch.Groups["Diameter"].Value; string diameter = diameterMatch.Groups["Diameter"].Value;
string thread = threadMatch.Groups["Thread"].Value; string thread = threadMatch.Groups["Thread"].Value;
return $"{_title} {(typeMatch.Success ? "длинный " : string.Empty)}{diameter}-Rp {thread}"; output = $"{_title} {(typeMatch.Success ? "длинный " : string.Empty)}{diameter}-Rp {thread}";
return true;
} }
} }

View File

@ -5,22 +5,25 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ThreadTPieceExternal : DrinkingWaterHeatingFitting public class ThreadTPieceExternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Тройник RAUTITAN с наружной резьбой"; protected override string _title => "Тройник RAUTITAN с наружной резьбой";
protected override string? BuildRhSolutionsName(string query)
public override bool TryQueryModify(string input, out string output)
{ {
MatchCollection diametersMatches = _diameter.Matches(query); output = string.Empty;
MatchCollection diametersMatches = _diameter.Matches(input);
if (diametersMatches.Count == 0) if (diametersMatches.Count == 0)
{ {
return null; return false;
} }
string thread = _thread.Match(query).Groups["Thread"].Value; string thread = _thread.Match(input).Groups["Thread"].Value;
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray(); int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
if (diameters.Length == 1) if (diameters.Length == 1)
{ {
return $"{_title} {diameters[0]}-{diameters[0]}-R {thread}"; output = $"{_title} {diameters[0]}-{diameters[0]}-R {thread}";
} }
else else
{ {
return $"{_title} {diameters[0]}-{diameters[1]}-R {thread}"; output = $"{_title} {diameters[0]}-{diameters[1]}-R {thread}";
} }
return true;
} }
} }

View File

@ -4,36 +4,38 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ThreadTPieceInternal : DrinkingWaterHeatingFitting public class ThreadTPieceInternal : DrinkingWaterHeatingFitting
{ {
protected override string? BuildRhSolutionsName(string query) public override bool TryQueryModify(string input, out string output)
{ {
MatchCollection diametersMatches = _diameter.Matches(query); output = string.Empty;
MatchCollection diametersMatches = _diameter.Matches(input);
if (diametersMatches.Count == 0) if (diametersMatches.Count == 0)
{ {
return null; return false;
} }
string thread = _thread.Match(query).Groups["Thread"].Value; string thread = _thread.Match(input).Groups["Thread"].Value;
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray(); int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
if (diameters.Length == 1) if (diameters.Length == 1)
{ {
if (diameters[0] < 25) if (diameters[0] < 25)
{ {
return $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}"; output = $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}";
} }
else else
{ {
return $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}"; output = $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}";
} }
} }
else else
{ {
if (diameters[0] < 25) if (diameters[0] < 25)
{ {
return $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}"; output = $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}";
} }
else else
{ {
return $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}"; output = $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}";
} }
} }
return true;
} }
} }

View File

@ -1,6 +1,4 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
@ -30,48 +28,29 @@ public class DrinkingWaterHeatingPipe : IProductQueryModifier
["отр"] = "прям.отрезки" ["отр"] = "прям.отрезки"
}; };
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) public bool TryQueryModify(string input, out string output)
{ {
queryString = QueryString.Empty; output = string.Empty;
string query = collection["query"].ToString(); var diameterMatch = _diameter.Match(input);
if (string.IsNullOrEmpty(query))
{
return false;
}
string? result = BuildRhSolutionsName(query);
if (result != null)
{
QueryBuilder qb = new()
{
{ "query", result }
};
queryString = qb.ToQueryString();
return true;
}
return false;
}
protected virtual string? BuildRhSolutionsName(string query)
{
var diameterMatch = _diameter.Match(query);
if (!diameterMatch.Success) if (!diameterMatch.Success)
{ {
return null; return false;
} }
var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value); var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value);
var typeMatch = _type.Match(query); var typeMatch = _type.Match(input);
if (typeMatch.Success) if (typeMatch.Success)
{ {
var type = typeMatch.Groups["Type"].Value; var type = typeMatch.Groups["Type"].Value;
return $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}"; output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}";
} }
else if (diameter < 32) else if (diameter < 32)
{ {
return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}"; output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}";
} }
else else
{ {
return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}"; output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}";
} }
return true;
} }
} }

View File

@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Http; namespace RhSolutions.QueryModifiers;
namespace RhSolutions.QueryModifiers;
public interface IProductQueryModifier public interface IProductQueryModifier
{ {
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString); public bool TryQueryModify(string query, out string queryModified);
} }