0
0

Add Sleeve Query modifier

This commit is contained in:
Serghei Cebotari 2023-09-21 08:20:13 +03:00
parent 12b557f53d
commit 38e5eb0393
2 changed files with 40 additions and 0 deletions

View File

@ -6,6 +6,8 @@ public class ProductQueryModifierFactory
{ {
switch (productTypeName) switch (productTypeName)
{ {
case "Монтажная гильза":
return new SleeveQueryModifier();
case "Тройник RAUTITAN": case "Тройник RAUTITAN":
return new TPieceQueryModifier(); return new TPieceQueryModifier();
default: default:

View File

@ -0,0 +1,38 @@
using System.Text.RegularExpressions;
using System.Text;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
public class SleeveQueryModifier : IProductQueryModifier
{
private readonly string pattern = @"(\b16|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);
StringBuilder sb = new();
sb.Append("Монтажная гильза ");
if (matches.Count > 0)
{
sb.Append(matches.First());
}
else
{
return false;
}
QueryBuilder qb = new()
{
{"query", sb.ToString() }
};
queryString = qb.ToQueryString();
return true;
}
}
}