aboutsummaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2021-11-29 11:26:25 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2021-11-29 11:26:25 +0300
commit0fe8e038af7f33eae824bba263e7c54dea829679 (patch)
treeb71636e6ee0c558f491bccd93c0236dbccbc67d6 /Assistant
parentf5234e956c79d3019e975a4d3550574c92f769e7 (diff)
Добавлен кэшинг результатов запроса, интерфейс IProduct
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/IProduct.cs9
-rw-r--r--Assistant/Product.cs21
-rw-r--r--Assistant/SkuAssist.cs16
3 files changed, 37 insertions, 9 deletions
diff --git a/Assistant/IProduct.cs b/Assistant/IProduct.cs
new file mode 100644
index 0000000..aca3ff5
--- /dev/null
+++ b/Assistant/IProduct.cs
@@ -0,0 +1,9 @@
+namespace Rehau.Sku.Assist
+{
+ interface IProduct
+ {
+ string Sku { get; }
+ string Name { get; }
+ string Uri { get; }
+ }
+}
diff --git a/Assistant/Product.cs b/Assistant/Product.cs
new file mode 100644
index 0000000..17a7065
--- /dev/null
+++ b/Assistant/Product.cs
@@ -0,0 +1,21 @@
+namespace Rehau.Sku.Assist
+{
+ public class Product : IProduct
+ {
+ public string Sku { get; }
+ public string Name { get; }
+
+ public string Uri => throw new System.NotImplementedException();
+
+ public Product(string sku, string name)
+ {
+ Sku = sku;
+ Name = name;
+ }
+
+ public override string ToString()
+ {
+ return $"{this.Name} ({this.Sku})";
+ }
+ }
+} \ No newline at end of file
diff --git a/Assistant/SkuAssist.cs b/Assistant/SkuAssist.cs
index 1167274..9eb3328 100644
--- a/Assistant/SkuAssist.cs
+++ b/Assistant/SkuAssist.cs
@@ -1,8 +1,8 @@
-using System.Net.Http;
-using System.Threading.Tasks;
-using AngleSharp;
+using AngleSharp;
using System.Linq;
using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
namespace Rehau.Sku.Assist
{
@@ -23,16 +23,14 @@ namespace Rehau.Sku.Assist
return await context.OpenAsync(req => req.Content(source));
}
- public static string GetResultFromDocument(AngleSharp.Dom.IDocument document)
+ public static IProduct GetProductFromDocument(AngleSharp.Dom.IDocument document)
{
- var result = document
+ return document
.All
.Where(e => e.ClassName == "product-item__desc-top")
- .Select(e => new { sku = e.Children[0].TextContent, title = e.Children[1].TextContent.Trim(new[] { '\n', ' ' }) })
- .Where(t => !t.sku.Any(c => char.IsLetter(c)))
+ .Select(e => new Product(e.Children[0].TextContent, e.Children[1].TextContent.Trim(new[] { '\n', ' ' })))
+ // .Where(product => !product.Sku.Any(c => char.IsLetter(c)))
.FirstOrDefault();
-
- return result == null ? "Не найдено" : $"{result.title} ({result.sku})";
}
}
}