0
0

Add coupling query modifier

This commit is contained in:
Serghei Cebotari 2023-10-01 22:14:47 +03:00
parent aa330461c6
commit fe96662905
3 changed files with 74 additions and 28 deletions

View File

@ -24,6 +24,11 @@ public class ProductQueryModifierTests
public void TPieceTest(string productType, string query, string modified) => public void TPieceTest(string productType, string query, string modified) =>
Test(productType, query, 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) public void Test(string productType, string query, string modified)
{ {
Dictionary<string, StringValues> queryPair = new() Dictionary<string, StringValues> queryPair = new()

View 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;
}
}
}
}

View File

@ -1,4 +1,4 @@
namespace RhSolutions.Api.Services; namespace RhSolutions.Api.Services;
public class ProductQueryModifierFactory public class ProductQueryModifierFactory
{ {
@ -10,6 +10,8 @@ public class ProductQueryModifierFactory
return new SleeveQueryModifier(); return new SleeveQueryModifier();
case "Тройник RAUTITAN": case "Тройник RAUTITAN":
return new TPieceQueryModifier(); return new TPieceQueryModifier();
case "Муфта соединительная":
return new CouplingModifier();
case "Flex": case "Flex":
return new FlexPipeQueryModifier(); return new FlexPipeQueryModifier();
case "Stabil": case "Stabil":