diff --git a/RhSolutions.Api.Tests/RautitanFittingsTests.cs b/RhSolutions.Api.Tests/RautitanFittingsTests.cs index 0233fad..ba11999 100644 --- a/RhSolutions.Api.Tests/RautitanFittingsTests.cs +++ b/RhSolutions.Api.Tests/RautitanFittingsTests.cs @@ -17,6 +17,10 @@ public class RautitanFittingsTests : ProductQueryModifierTests [TestCase("Муфта соединительная переходная 20x16 для труб из сшитого полиэтилена аксиальный", "Муфта соединительная переходная 20-16")] public void CouplingTest(string query, string modified) => Execute(productType: "Муфта соединительная", query, modified); + + [TestCase("Переходник с внутренней резьбой 16xG 3/4\" для труб из сшитого полиэтилена аксиальный", "Переходник с внутренней резьбой -угольник-переходник 16 3/4")] + public void AdapterInternalTest(string query, string modified) + => Execute(productType: "Переходник на внутреннюю резьбу", query, modified); [TestCase("Угольник 90°, 40 PX", "Угольник RAUTITAN -PLATINUM 90 40")] public void ElbowTest(string query, string modified) @@ -34,12 +38,9 @@ public class RautitanFittingsTests : ProductQueryModifierTests [TestCase("Соединение угловое с накидной гайкой 16 х 1/2\", латунь", "Угольник-переходник с накидной гайкой 16 1/2")] public void ScrewcapElbowTest(string query, string modified) => Execute(productType: "Угольник с накидной гайкой", query, modified); - - [TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник настенный с внутренней резьбой 16-Rp1/2-16")] - public void ThreadTPieceWallTest(string query, string modified) - => Execute(productType: "Тройник RAUTITAN резьбовой настенный", query, modified); - + [TestCase("Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25 RX+", "Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25")] + [TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник настенный с внутренней резьбой 16-Rp1/2-16")] public void ThreadTPieceInternalTest(string query, string modified) => Execute(productType: "Тройник RAUTITAN резьбовой внутренний", query, modified); diff --git a/RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj b/RhSolutions.Api.Tests/RhSolutions.QueryModifiers.Tests.csproj similarity index 99% rename from RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj rename to RhSolutions.Api.Tests/RhSolutions.QueryModifiers.Tests.csproj index 4ce8b7c..e47c6d3 100644 --- a/RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj +++ b/RhSolutions.Api.Tests/RhSolutions.QueryModifiers.Tests.csproj @@ -4,7 +4,6 @@ net6.0 enable enable - false diff --git a/RhSolutions.Api.Tests/Usings.cs b/RhSolutions.Api.Tests/Usings.cs index cefced4..3a00a34 100644 --- a/RhSolutions.Api.Tests/Usings.cs +++ b/RhSolutions.Api.Tests/Usings.cs @@ -1 +1,2 @@ -global using NUnit.Framework; \ No newline at end of file +global using NUnit.Framework; +global using RhSolutions.QueryModifiers; \ No newline at end of file diff --git a/RhSolutions.Api/Middleware/QueryModifier.cs b/RhSolutions.Api/Middleware/QueryModifier.cs index 810c7dd..02756a6 100644 --- a/RhSolutions.Api/Middleware/QueryModifier.cs +++ b/RhSolutions.Api/Middleware/QueryModifier.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNetCore.Http.Extensions; -using RhSolutions.Api.Services; +using RhSolutions.Api.Services; +using RhSolutions.QueryModifiers; namespace RhSolutions.Api.Middleware; diff --git a/RhSolutions.Api/Program.cs b/RhSolutions.Api/Program.cs index 530be7f..006e312 100644 --- a/RhSolutions.Api/Program.cs +++ b/RhSolutions.Api/Program.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using RhSolutions.Models; using RhSolutions.Api.Services; using RhSolutions.Api.Middleware; +using RhSolutions.QueryModifiers; var builder = WebApplication.CreateBuilder(args); diff --git a/RhSolutions.Api/RhSolutions.Api.csproj b/RhSolutions.Api/RhSolutions.Api.csproj index 5f122f2..507302e 100644 --- a/RhSolutions.Api/RhSolutions.Api.csproj +++ b/RhSolutions.Api/RhSolutions.Api.csproj @@ -19,6 +19,10 @@ + + + + PreserveNewest diff --git a/RhSolutions.Api/Services/BlackPipeQueryModifier.cs b/RhSolutions.Api/Services/BlackPipeQueryModifier.cs deleted file mode 100644 index 14dd636..0000000 --- a/RhSolutions.Api/Services/BlackPipeQueryModifier.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class BlackPipeQueryModifier : PipeQueryModifier - { - protected override string diameterPattern =>@"([\b\D]|^)(?16|20|25)([\b\D]|$)"; - protected override string pipeName => "Black"; - protected override Dictionary diameterNames => new() - { - ["16"] = "16х2,2", - ["20"] = "20х2,8", - ["25"] = "25х3,5" - }; - } -} diff --git a/RhSolutions.Api/Services/BypassQueryModifier.cs b/RhSolutions.Api/Services/BypassQueryModifier.cs deleted file mode 100644 index 8ba3826..0000000 --- a/RhSolutions.Api/Services/BypassQueryModifier.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class BypassQueryModifier : IProductQueryModifier - { - public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) - { - queryString = QueryString.Empty; - return false; - } - } -} diff --git a/RhSolutions.Api/Services/CouplingModifier.cs b/RhSolutions.Api/Services/CouplingModifier.cs deleted file mode 100644 index 4abf440..0000000 --- a/RhSolutions.Api/Services/CouplingModifier.cs +++ /dev/null @@ -1,39 +0,0 @@ - -using System.Text.RegularExpressions; -using Microsoft.AspNetCore.Http.Extensions; - -namespace RhSolutions.Api.Services -{ - public class CouplingModifier : IProductQueryModifier - { - private string pattern { get; } = @"([\b\D]|^)?(?16|20|25|32|40|50|63)([\b\D]|$)?"; - 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 || matches.Count > 1 && matches[0].Groups["Diameter"].Value == matches[1].Groups["Diameter"].Value) - { - qb.Add("query", $"Муфта соединительная равнопроходная {matches[0].Groups["Diameter"].Value}"); - } - else - { - qb.Add("query", $"Муфта соединительная переходная {matches[0].Groups["Diameter"].Value}-{matches[1].Groups["Diameter"].Value}"); - } - queryString = qb.ToQueryString(); - return true; - } - } - } -} diff --git a/RhSolutions.Api/Services/FlexPipeQueryModifier.cs b/RhSolutions.Api/Services/FlexPipeQueryModifier.cs deleted file mode 100644 index a96ec80..0000000 --- a/RhSolutions.Api/Services/FlexPipeQueryModifier.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class FlexPipeQueryModifier : PipeQueryModifier { } -} diff --git a/RhSolutions.Api/Services/IProductQueryModifier.cs b/RhSolutions.Api/Services/IProductQueryModifier.cs deleted file mode 100644 index 3892a39..0000000 --- a/RhSolutions.Api/Services/IProductQueryModifier.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public interface IProductQueryModifier - { - public bool TryQueryModify(IQueryCollection collection, out QueryString queryString); - } -} diff --git a/RhSolutions.Api/Services/PinkPipeQueryModifier.cs b/RhSolutions.Api/Services/PinkPipeQueryModifier.cs deleted file mode 100644 index 52afd9a..0000000 --- a/RhSolutions.Api/Services/PinkPipeQueryModifier.cs +++ /dev/null @@ -1,24 +0,0 @@ - -namespace RhSolutions.Api.Services -{ - public class PinkPipeQueryModifier : PipeQueryModifier - { - protected override string pipeName => "Pink+"; - protected override Dictionary diameterNames => new() - { - ["16"] = "16х2,2", - ["20"] = "20х2,8", - ["25"] = "25х3,5", - ["32"] = "32х4,4", - ["40"] = "40х5,5", - ["50"] = "50х6,9", - ["63"] = "63х8,7" - }; - protected override Dictionary makeUpNames => new() - { - ["бухт"] = "бухта", - ["штанг"] = "прямые отрезки", - ["отр"] = "прямые отрезки" - }; - } -} diff --git a/RhSolutions.Api/Services/PipeQueryModifier.cs b/RhSolutions.Api/Services/PipeQueryModifier.cs deleted file mode 100644 index 88c2275..0000000 --- a/RhSolutions.Api/Services/PipeQueryModifier.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Text.RegularExpressions; -using Microsoft.AspNetCore.Http.Extensions; - -namespace RhSolutions.Api.Services -{ - public class PipeQueryModifier : IProductQueryModifier - { - protected virtual string diameterPattern { get; } = @"([\b\D]|^)(?16|20|25|32|40|50|63)([\b\D]|$)"; - protected virtual string typePattern { get; } = @"бухт|отр|штанг"; - protected virtual string pipeName { get; } = "Flex"; - protected virtual Dictionary diameterNames { get; } = new() - { - ["16"] = "16x2,2", - ["20"] = "20x2,8", - ["25"] = "25x3,5", - ["32"] = "32x4,4", - ["40"] = "40x5,5", - ["50"] = "50x6,9", - ["63"] = "63x8,6" - }; - - protected virtual Dictionary makeUpNames { get; } = new() - { - ["бухт"] = "бухта", - ["штанг"] = "прям.отрезки", - ["отр"] = "прям.отрезки" - }; - - public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) - { - queryString = QueryString.Empty; - string query = collection["query"].ToString(); - if (string.IsNullOrEmpty(query)) - { - return false; - } - - var diameterMatches = Regex.Matches(query, diameterPattern); - if (diameterMatches.Count == 0) - { - return false; - } - - var typeMatches = Regex.Matches(query, typePattern); - var diameter = diameterMatches.First().Groups["Diameter"].Value; - string? type = typeMatches.FirstOrDefault()?.Value; - - string result = - $"Труба {pipeName} {diameterNames[diameter]} {(type != null ? makeUpNames[type] : int.Parse(diameter) < 32 ? makeUpNames["бухт"] : makeUpNames["отр"])}"; - - QueryBuilder qb = new() - { - { "query", result } - }; - queryString = qb.ToQueryString(); - return true; - } - } -} diff --git a/RhSolutions.Api/Services/ScrewcapElbowModifier.cs b/RhSolutions.Api/Services/ScrewcapElbowModifier.cs deleted file mode 100644 index c299146..0000000 --- a/RhSolutions.Api/Services/ScrewcapElbowModifier.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class ScrewcapElbowModifier : AdapterModifier - { - protected override string name => "Угольник-переходник с накидной гайкой"; - } -} diff --git a/RhSolutions.Api/Services/SleeveQueryModifier.cs b/RhSolutions.Api/Services/SleeveQueryModifier.cs deleted file mode 100644 index e95c82e..0000000 --- a/RhSolutions.Api/Services/SleeveQueryModifier.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Text.RegularExpressions; -using System.Text; -using Microsoft.AspNetCore.Http.Extensions; - -namespace RhSolutions.Api.Services -{ - public class SleeveQueryModifier : IProductQueryModifier - { - private readonly string pattern = @"\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); - 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; - } - } -} diff --git a/RhSolutions.Api/Services/StabilPipeQueryModifier.cs b/RhSolutions.Api/Services/StabilPipeQueryModifier.cs deleted file mode 100644 index d345bb6..0000000 --- a/RhSolutions.Api/Services/StabilPipeQueryModifier.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class StabilPipeQueryModifier : PipeQueryModifier - { - protected override string diameterPattern => @"([\b\D]|^)(?16|20|25|32|40)([\b\D]|$)"; - protected override string pipeName => "Stabil -PLATINUM"; - protected override Dictionary diameterNames => new() - { - ["16"] = "16,2х2,6", - ["20"] = "20х2,9", - ["25"] = "25х3,7", - ["32"] = "32х4,7", - ["40"] = "40х6,0" - }; - } -} diff --git a/RhSolutions.Api/Services/TPieceQueryModifier.cs b/RhSolutions.Api/Services/TPieceQueryModifier.cs deleted file mode 100644 index be00ed7..0000000 --- a/RhSolutions.Api/Services/TPieceQueryModifier.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.AspNetCore.Http.Extensions; -using System.Text; -using System.Text.RegularExpressions; - -namespace RhSolutions.Api.Services -{ - public class TPieceQueryModifier : IProductQueryModifier - { - private readonly string pattern = @"16|20|25|32|40|50|63"; - - 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("Тройник RAUTITAN -PLATINUM"); - if (matches.Count == 1) - { - sb.Append($" {matches.First().Value}-{matches.First().Value}-{matches.First().Value}"); - } - else if (matches.Count >= 3) - { - sb.Append($" {matches[0].Value}-{matches[1].Value}-{matches[2].Value}"); - } - else - { - return false; - } - QueryBuilder qb = new() - { - { "query", sb.ToString() } - }; - queryString = qb.ToQueryString(); - return true; - } - } -} diff --git a/RhSolutions.Api/Services/ThreadElbowExternalModifier.cs b/RhSolutions.Api/Services/ThreadElbowExternalModifier.cs deleted file mode 100644 index aee181d..0000000 --- a/RhSolutions.Api/Services/ThreadElbowExternalModifier.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class ThreadElbowExternalModifier : AdapterModifier - { - protected override string name => "Угольник-переходник с наружной резьбой"; - } -} diff --git a/RhSolutions.Api/Services/ThreadElbowInternalModifier.cs b/RhSolutions.Api/Services/ThreadElbowInternalModifier.cs deleted file mode 100644 index f04d371..0000000 --- a/RhSolutions.Api/Services/ThreadElbowInternalModifier.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace RhSolutions.Api.Services -{ - public class ThreadElbowInternalModifier : AdapterModifier - { - protected override string name => "Угольник-переходник с внутренней резьбой"; - } -} diff --git a/RhSolutions.Api/Services/ThreadTPieceInternal.cs b/RhSolutions.Api/Services/ThreadTPieceInternal.cs deleted file mode 100644 index 41672f1..0000000 --- a/RhSolutions.Api/Services/ThreadTPieceInternal.cs +++ /dev/null @@ -1,20 +0,0 @@ - -using System.Text.RegularExpressions; - -namespace RhSolutions.Api.Services; - -public class ThreadTPieceInternal : ThreadTPieceWall -{ - protected override string ConstructName(MatchCollection diameters, Match thread) - { - Capture t = thread.Groups["Thread"].Captures.First(); - if (diameters.Count == 1) - { - return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[0]}"; - } - else - { - return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[1]}"; - } - } -} diff --git a/RhSolutions.Api/Services/AdapterExternalModifier.cs b/RhSolutions.QueryModifiers/AdapterExternalModifier.cs similarity index 81% rename from RhSolutions.Api/Services/AdapterExternalModifier.cs rename to RhSolutions.QueryModifiers/AdapterExternalModifier.cs index 5943e70..1e7bc5d 100644 --- a/RhSolutions.Api/Services/AdapterExternalModifier.cs +++ b/RhSolutions.QueryModifiers/AdapterExternalModifier.cs @@ -1,4 +1,4 @@ -namespace RhSolutions.Api.Services +namespace RhSolutions.QueryModifiers { public class AdapterExternalModifier : AdapterModifier { diff --git a/RhSolutions.Api/Services/AdapterInternalModifier.cs b/RhSolutions.QueryModifiers/AdapterInternalModifier.cs similarity index 54% rename from RhSolutions.Api/Services/AdapterInternalModifier.cs rename to RhSolutions.QueryModifiers/AdapterInternalModifier.cs index b79ca96..7761dd1 100644 --- a/RhSolutions.Api/Services/AdapterInternalModifier.cs +++ b/RhSolutions.QueryModifiers/AdapterInternalModifier.cs @@ -1,7 +1,7 @@ -namespace RhSolutions.Api.Services +namespace RhSolutions.QueryModifiers { public class AdapterInternalModifier : AdapterModifier { - protected override string name => "Переходник с внутренней резьбой"; + protected override string name => "Переходник с внутренней резьбой -угольник-переходник"; } } diff --git a/RhSolutions.Api/Services/AdapterModifier.cs b/RhSolutions.QueryModifiers/AdapterModifier.cs similarity index 93% rename from RhSolutions.Api/Services/AdapterModifier.cs rename to RhSolutions.QueryModifiers/AdapterModifier.cs index 758b49f..0ebe40d 100644 --- a/RhSolutions.Api/Services/AdapterModifier.cs +++ b/RhSolutions.QueryModifiers/AdapterModifier.cs @@ -1,8 +1,8 @@ - using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -namespace RhSolutions.Api.Services +namespace RhSolutions.QueryModifiers { public abstract class AdapterModifier : IProductQueryModifier { diff --git a/RhSolutions.Api/Services/AdapterScrewcapModifier.cs b/RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs similarity index 82% rename from RhSolutions.Api/Services/AdapterScrewcapModifier.cs rename to RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs index 2575bd5..9841891 100644 --- a/RhSolutions.Api/Services/AdapterScrewcapModifier.cs +++ b/RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs @@ -1,4 +1,4 @@ -namespace RhSolutions.Api.Services +namespace RhSolutions.QueryModifiers { public class AdapterScrewcapModifier : AdapterModifier { diff --git a/RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs b/RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs new file mode 100644 index 0000000..d59db67 --- /dev/null +++ b/RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs @@ -0,0 +1,13 @@ +namespace RhSolutions.QueryModifiers; + +public class BlackPipeQueryModifier : PipeQueryModifier +{ + protected override string diameterPattern => @"([\b\D]|^)(?16|20|25)([\b\D]|$)"; + protected override string pipeName => "Black"; + protected override Dictionary diameterNames => new() + { + ["16"] = "16х2,2", + ["20"] = "20х2,8", + ["25"] = "25х3,5" + }; +} diff --git a/RhSolutions.QueryModifiers/BypassQueryModifier.cs b/RhSolutions.QueryModifiers/BypassQueryModifier.cs new file mode 100644 index 0000000..68d3cb2 --- /dev/null +++ b/RhSolutions.QueryModifiers/BypassQueryModifier.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Http; + +namespace RhSolutions.QueryModifiers; + +public class BypassQueryModifier : IProductQueryModifier +{ + public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) + { + queryString = QueryString.Empty; + return false; + } +} diff --git a/RhSolutions.QueryModifiers/CouplingModifier.cs b/RhSolutions.QueryModifiers/CouplingModifier.cs new file mode 100644 index 0000000..e8a1739 --- /dev/null +++ b/RhSolutions.QueryModifiers/CouplingModifier.cs @@ -0,0 +1,38 @@ +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; + +namespace RhSolutions.QueryModifiers; + +public class CouplingModifier : IProductQueryModifier +{ + private string pattern { get; } = @"([\b\D]|^)?(?16|20|25|32|40|50|63)([\b\D]|$)?"; + 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 || matches.Count > 1 && matches[0].Groups["Diameter"].Value == matches[1].Groups["Diameter"].Value) + { + qb.Add("query", $"Муфта соединительная равнопроходная {matches[0].Groups["Diameter"].Value}"); + } + else + { + qb.Add("query", $"Муфта соединительная переходная {matches[0].Groups["Diameter"].Value}-{matches[1].Groups["Diameter"].Value}"); + } + queryString = qb.ToQueryString(); + return true; + } + } +} diff --git a/RhSolutions.Api/Services/ElbowModifier.cs b/RhSolutions.QueryModifiers/ElbowModifier.cs similarity index 93% rename from RhSolutions.Api/Services/ElbowModifier.cs rename to RhSolutions.QueryModifiers/ElbowModifier.cs index d3367f7..05ca9b4 100644 --- a/RhSolutions.Api/Services/ElbowModifier.cs +++ b/RhSolutions.QueryModifiers/ElbowModifier.cs @@ -1,8 +1,8 @@ - using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -namespace RhSolutions.Api.Services +namespace RhSolutions.QueryModifiers { public class ElbowModifier : IProductQueryModifier { diff --git a/RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs b/RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs new file mode 100644 index 0000000..9bee225 --- /dev/null +++ b/RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs @@ -0,0 +1,3 @@ +namespace RhSolutions.QueryModifiers; + +public class FlexPipeQueryModifier : PipeQueryModifier { } \ No newline at end of file diff --git a/RhSolutions.QueryModifiers/IProductQueryModifier.cs b/RhSolutions.QueryModifiers/IProductQueryModifier.cs new file mode 100644 index 0000000..508aba5 --- /dev/null +++ b/RhSolutions.QueryModifiers/IProductQueryModifier.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Http; + +namespace RhSolutions.QueryModifiers; + +public interface IProductQueryModifier +{ + public bool TryQueryModify(IQueryCollection collection, out QueryString queryString); +} diff --git a/RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs b/RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs new file mode 100644 index 0000000..c76077f --- /dev/null +++ b/RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs @@ -0,0 +1,22 @@ +namespace RhSolutions.QueryModifiers; + +public class PinkPipeQueryModifier : PipeQueryModifier +{ + protected override string pipeName => "Pink+"; + protected override Dictionary diameterNames => new() + { + ["16"] = "16х2,2", + ["20"] = "20х2,8", + ["25"] = "25х3,5", + ["32"] = "32х4,4", + ["40"] = "40х5,5", + ["50"] = "50х6,9", + ["63"] = "63х8,7" + }; + protected override Dictionary makeUpNames => new() + { + ["бухт"] = "бухта", + ["штанг"] = "прямые отрезки", + ["отр"] = "прямые отрезки" + }; +} diff --git a/RhSolutions.QueryModifiers/PipeQueryModifier.cs b/RhSolutions.QueryModifiers/PipeQueryModifier.cs new file mode 100644 index 0000000..2126c55 --- /dev/null +++ b/RhSolutions.QueryModifiers/PipeQueryModifier.cs @@ -0,0 +1,59 @@ +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; + +namespace RhSolutions.QueryModifiers; + +public class PipeQueryModifier : IProductQueryModifier +{ + protected virtual string diameterPattern { get; } = @"([\b\D]|^)(?16|20|25|32|40|50|63)([\b\D]|$)"; + protected virtual string typePattern { get; } = @"бухт|отр|штанг"; + protected virtual string pipeName { get; } = "Flex"; + protected virtual Dictionary diameterNames { get; } = new() + { + ["16"] = "16x2,2", + ["20"] = "20x2,8", + ["25"] = "25x3,5", + ["32"] = "32x4,4", + ["40"] = "40x5,5", + ["50"] = "50x6,9", + ["63"] = "63x8,6" + }; + + protected virtual Dictionary makeUpNames { get; } = new() + { + ["бухт"] = "бухта", + ["штанг"] = "прям.отрезки", + ["отр"] = "прям.отрезки" + }; + + public bool TryQueryModify(IQueryCollection collection, out QueryString queryString) + { + queryString = QueryString.Empty; + string query = collection["query"].ToString(); + if (string.IsNullOrEmpty(query)) + { + return false; + } + + var diameterMatches = Regex.Matches(query, diameterPattern); + if (diameterMatches.Count == 0) + { + return false; + } + + var typeMatches = Regex.Matches(query, typePattern); + var diameter = diameterMatches.First().Groups["Diameter"].Value; + string? type = typeMatches.FirstOrDefault()?.Value; + + string result = + $"Труба {pipeName} {diameterNames[diameter]} {(type != null ? makeUpNames[type] : int.Parse(diameter) < 32 ? makeUpNames["бухт"] : makeUpNames["отр"])}"; + + QueryBuilder qb = new() + { + { "query", result } + }; + queryString = qb.ToQueryString(); + return true; + } +} diff --git a/RhSolutions.Api/Services/ProductQueryModifierFactory.cs b/RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs similarity index 95% rename from RhSolutions.Api/Services/ProductQueryModifierFactory.cs rename to RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs index b0f7b85..32d5e5e 100644 --- a/RhSolutions.Api/Services/ProductQueryModifierFactory.cs +++ b/RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs @@ -1,4 +1,4 @@ -namespace RhSolutions.Api.Services; +namespace RhSolutions.QueryModifiers; public class ProductQueryModifierFactory { @@ -15,7 +15,7 @@ public class ProductQueryModifierFactory case "Тройник RAUTITAN резьбовой внутренний": return new ThreadTPieceInternal(); case "Тройник RAUTITAN резьбовой настенный": - return new ThreadTPieceWall(); + return new ThreadTPieceInternal(); case "Переходник на наружную резьбу": return new AdapterExternalModifier(); case "Переходник на внутреннюю резьбу": diff --git a/RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj b/RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj new file mode 100644 index 0000000..0132e39 --- /dev/null +++ b/RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs b/RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs new file mode 100644 index 0000000..b83236d --- /dev/null +++ b/RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs @@ -0,0 +1,6 @@ +namespace RhSolutions.QueryModifiers; + +public class ScrewcapElbowModifier : AdapterModifier +{ + protected override string name => "Угольник-переходник с накидной гайкой"; +} diff --git a/RhSolutions.QueryModifiers/SleeveQueryModifier.cs b/RhSolutions.QueryModifiers/SleeveQueryModifier.cs new file mode 100644 index 0000000..788a3a2 --- /dev/null +++ b/RhSolutions.QueryModifiers/SleeveQueryModifier.cs @@ -0,0 +1,38 @@ +using System.Text.RegularExpressions; +using System.Text; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Http; + +namespace RhSolutions.QueryModifiers; + +public class SleeveQueryModifier : IProductQueryModifier +{ + private readonly string pattern = @"\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); + 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; + } +} diff --git a/RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs b/RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs new file mode 100644 index 0000000..2ace1f3 --- /dev/null +++ b/RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs @@ -0,0 +1,15 @@ +namespace RhSolutions.QueryModifiers; + +public class StabilPipeQueryModifier : PipeQueryModifier +{ + protected override string diameterPattern => @"([\b\D]|^)(?16|20|25|32|40)([\b\D]|$)"; + protected override string pipeName => "Stabil -PLATINUM"; + protected override Dictionary diameterNames => new() + { + ["16"] = "16,2х2,6", + ["20"] = "20х2,9", + ["25"] = "25х3,7", + ["32"] = "32х4,7", + ["40"] = "40х6,0" + }; +} diff --git a/RhSolutions.QueryModifiers/TPieceQueryModifier.cs b/RhSolutions.QueryModifiers/TPieceQueryModifier.cs new file mode 100644 index 0000000..87c5b61 --- /dev/null +++ b/RhSolutions.QueryModifiers/TPieceQueryModifier.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; +using System.Text; +using System.Text.RegularExpressions; + +namespace RhSolutions.QueryModifiers; + +public class TPieceQueryModifier : IProductQueryModifier +{ + private readonly string pattern = @"16|20|25|32|40|50|63"; + + 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("Тройник RAUTITAN -PLATINUM"); + if (matches.Count == 1) + { + sb.Append($" {matches.First().Value}-{matches.First().Value}-{matches.First().Value}"); + } + else if (matches.Count >= 3) + { + sb.Append($" {matches[0].Value}-{matches[1].Value}-{matches[2].Value}"); + } + else + { + return false; + } + QueryBuilder qb = new() + { + { "query", sb.ToString() } + }; + queryString = qb.ToQueryString(); + return true; + } +} diff --git a/RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs b/RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs new file mode 100644 index 0000000..3297f44 --- /dev/null +++ b/RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs @@ -0,0 +1,6 @@ +namespace RhSolutions.QueryModifiers; + +public class ThreadElbowExternalModifier : AdapterModifier +{ + protected override string name => "Угольник-переходник с наружной резьбой"; +} diff --git a/RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs b/RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs new file mode 100644 index 0000000..88801e7 --- /dev/null +++ b/RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs @@ -0,0 +1,6 @@ +namespace RhSolutions.QueryModifiers; + +public class ThreadElbowInternalModifier : AdapterModifier +{ + protected override string name => "Угольник-переходник с внутренней резьбой"; +} diff --git a/RhSolutions.Api/Services/ThreadTPieceExternal.cs b/RhSolutions.QueryModifiers/ThreadTPieceExternal.cs similarity index 75% rename from RhSolutions.Api/Services/ThreadTPieceExternal.cs rename to RhSolutions.QueryModifiers/ThreadTPieceExternal.cs index 5515c6b..b5c910b 100644 --- a/RhSolutions.Api/Services/ThreadTPieceExternal.cs +++ b/RhSolutions.QueryModifiers/ThreadTPieceExternal.cs @@ -1,9 +1,8 @@ - -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; -namespace RhSolutions.Api.Services; +namespace RhSolutions.QueryModifiers; -public class ThreadTPieceExternal : ThreadTPieceWall +public class ThreadTPieceExternal : ThreadTPieceInternal { protected override string ConstructName(MatchCollection diameters, Match thread) { diff --git a/RhSolutions.Api/Services/ThreadTPieceWall.cs b/RhSolutions.QueryModifiers/ThreadTPieceWall.cs similarity index 56% rename from RhSolutions.Api/Services/ThreadTPieceWall.cs rename to RhSolutions.QueryModifiers/ThreadTPieceWall.cs index 76f3b75..8e11a91 100644 --- a/RhSolutions.Api/Services/ThreadTPieceWall.cs +++ b/RhSolutions.QueryModifiers/ThreadTPieceWall.cs @@ -1,10 +1,10 @@ - using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -namespace RhSolutions.Api.Services; +namespace RhSolutions.QueryModifiers; -public class ThreadTPieceWall : IProductQueryModifier +public class ThreadTPieceInternal : IProductQueryModifier { private string diameterPattern = "16|20|25|32|40|50|63"; private string threadPattern = @"(\D|^)(?1\s+1/4|1\s+1/2|1/2|3/4|2|1)(\D|$)"; @@ -40,11 +40,25 @@ public class ThreadTPieceWall : IProductQueryModifier Capture t = thread.Groups["Thread"].Captures.First(); if (diameters.Count == 1) { - return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[0]}"; + if (int.Parse(diameters[0].Value) < 25) + { + return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[0]}"; + } + else + { + return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[0]}"; + } } else { - return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[1]}"; + if (int.Parse(diameters[0].Value) < 25) + { + return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[1]}"; + } + else + { + return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[1]}"; + } } } } diff --git a/RhSolutions.sln b/RhSolutions.sln index 22fbf80..c719061 100644 --- a/RhSolutions.sln +++ b/RhSolutions.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.Api", "RhSolutions.Api\RhSolutions.Api.csproj", "{FD778359-7E92-4B5C-A4F9-7942A28E58F5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.Api.Tests", "RhSolutions.Api.Tests\RhSolutions.Api.Tests.csproj", "{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.QueryModifiers.Tests", "RhSolutions.Api.Tests\RhSolutions.QueryModifiers.Tests.csproj", "{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.QueryModifiers", "RhSolutions.QueryModifiers\RhSolutions.QueryModifiers.csproj", "{0C96960B-859B-4376-882E-AA0EB203B1EA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -24,5 +26,9 @@ Global {9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Release|Any CPU.Build.0 = Release|Any CPU + {0C96960B-859B-4376-882E-AA0EB203B1EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C96960B-859B-4376-882E-AA0EB203B1EA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C96960B-859B-4376-882E-AA0EB203B1EA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C96960B-859B-4376-882E-AA0EB203B1EA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal