0
0

Add adapters modifiers

This commit is contained in:
Serghei Cebotari 2023-10-01 22:15:01 +03:00
parent fe96662905
commit be49549723
5 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,7 @@
namespace RhSolutions.Api.Services
{
public class AdapterExternalModifier : AdapterModifier
{
protected override string name => "Переходник с наружной резьбой";
}
}

View File

@ -0,0 +1,7 @@
namespace RhSolutions.Api.Services
{
public class AdapterInternalModifier : AdapterModifier
{
protected override string name => "Переходник с внутренней резьбой";
}
}

View File

@ -0,0 +1,39 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
public abstract class AdapterModifier : IProductQueryModifier
{
protected string pattern { get; } =
@"(?<Diameter>\b16|20|25|32|40|50|63\b)\D+(?<Thread>\b1\s+1/4|1\s+1/2|1/2|3/4|2|1\b)";
protected virtual string name { get; } = string.Empty;
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 < 0)
{
return false;
}
else
{
var match = matches.First();
var diameter = match.Groups["Diameter"].Captures.First();
var thread = match.Groups["Thread"].Captures.First();
QueryBuilder qb = new()
{
{"query", $"{name} {diameter} {thread}"}
};
queryString = qb.ToQueryString();
return true;
}
}
}
}

View File

@ -0,0 +1,7 @@
namespace RhSolutions.Api.Services
{
public class AdapterScrewcapModifier : AdapterModifier
{
protected override string name => "Переходник с накидной гайкой";
}
}

View File

@ -1,4 +1,4 @@
namespace RhSolutions.Api.Services;
namespace RhSolutions.Api.Services;
public class ProductQueryModifierFactory
{
@ -10,6 +10,12 @@ public class ProductQueryModifierFactory
return new SleeveQueryModifier();
case "Тройник RAUTITAN":
return new TPieceQueryModifier();
case "Переходник на наружную резьбу":
return new AdapterExternalModifier();
case "Переходник на внутреннюю резьбу":
return new AdapterInternalModifier();
case "Переходник с накидной гайкой":
return new AdapterScrewcapModifier();
case "Муфта соединительная":
return new CouplingModifier();
case "Flex":