Add adapters modifiers
This commit is contained in:
parent
fe96662905
commit
be49549723
7
RhSolutions.Api/Services/AdapterExternalModifier.cs
Normal file
7
RhSolutions.Api/Services/AdapterExternalModifier.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class AdapterExternalModifier : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Переходник с наружной резьбой";
|
||||||
|
}
|
||||||
|
}
|
7
RhSolutions.Api/Services/AdapterInternalModifier.cs
Normal file
7
RhSolutions.Api/Services/AdapterInternalModifier.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class AdapterInternalModifier : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Переходник с внутренней резьбой";
|
||||||
|
}
|
||||||
|
}
|
39
RhSolutions.Api/Services/AdapterModifier.cs
Normal file
39
RhSolutions.Api/Services/AdapterModifier.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
RhSolutions.Api/Services/AdapterScrewcapModifier.cs
Normal file
7
RhSolutions.Api/Services/AdapterScrewcapModifier.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class AdapterScrewcapModifier : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Переходник с накидной гайкой";
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
namespace RhSolutions.Api.Services;
|
namespace RhSolutions.Api.Services;
|
||||||
|
|
||||||
public class ProductQueryModifierFactory
|
public class ProductQueryModifierFactory
|
||||||
{
|
{
|
||||||
@ -10,6 +10,12 @@ public class ProductQueryModifierFactory
|
|||||||
return new SleeveQueryModifier();
|
return new SleeveQueryModifier();
|
||||||
case "Тройник RAUTITAN":
|
case "Тройник RAUTITAN":
|
||||||
return new TPieceQueryModifier();
|
return new TPieceQueryModifier();
|
||||||
|
case "Переходник на наружную резьбу":
|
||||||
|
return new AdapterExternalModifier();
|
||||||
|
case "Переходник на внутреннюю резьбу":
|
||||||
|
return new AdapterInternalModifier();
|
||||||
|
case "Переходник с накидной гайкой":
|
||||||
|
return new AdapterScrewcapModifier();
|
||||||
case "Муфта соединительная":
|
case "Муфта соединительная":
|
||||||
return new CouplingModifier();
|
return new CouplingModifier();
|
||||||
case "Flex":
|
case "Flex":
|
||||||
|
Loading…
Reference in New Issue
Block a user