Add coupling query modifier
This commit is contained in:
parent
aa330461c6
commit
fe96662905
@ -24,6 +24,11 @@ public class ProductQueryModifierTests
|
||||
public void TPieceTest(string productType, string query, string modified) =>
|
||||
Test(productType, query, modified);
|
||||
|
||||
[TestCase("Муфта соединительная", "муфта 20", "Муфта соединительная равнопроходная 20")]
|
||||
[TestCase("Муфта соединительная", "переходник 20-16", "Муфта соединительная переходная 20-16")]
|
||||
public void CouplingTest(string productType, string query, string modified) =>
|
||||
Test(productType, query, modified);
|
||||
|
||||
public void Test(string productType, string query, string modified)
|
||||
{
|
||||
Dictionary<string, StringValues> queryPair = new()
|
||||
|
39
RhSolutions.Api/Services/CouplingModifier.cs
Normal file
39
RhSolutions.Api/Services/CouplingModifier.cs
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class CouplingModifier : IProductQueryModifier
|
||||
{
|
||||
private string pattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||
{
|
||||
queryString = QueryString.Empty;
|
||||
var query = collection["query"].ToString();
|
||||
if (string.IsNullOrEmpty(query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var matches = Regex.Matches(query, pattern);
|
||||
if (matches.Count < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryBuilder qb = new();
|
||||
if (matches.Count < 2)
|
||||
{
|
||||
qb.Add("query", $"Муфта соединительная равнопроходная {matches[0]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
qb.Add("query", $"Муфта соединительная переходная {matches[0]}-{matches[1]}");
|
||||
}
|
||||
queryString = qb.ToQueryString();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace RhSolutions.Api.Services;
|
||||
namespace RhSolutions.Api.Services;
|
||||
|
||||
public class ProductQueryModifierFactory
|
||||
{
|
||||
@ -10,6 +10,8 @@ public class ProductQueryModifierFactory
|
||||
return new SleeveQueryModifier();
|
||||
case "Тройник RAUTITAN":
|
||||
return new TPieceQueryModifier();
|
||||
case "Муфта соединительная":
|
||||
return new CouplingModifier();
|
||||
case "Flex":
|
||||
return new FlexPipeQueryModifier();
|
||||
case "Stabil":
|
||||
|
Loading…
Reference in New Issue
Block a user