aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Api/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'RhSolutions.SkuParser.Api/Controllers')
-rw-r--r--RhSolutions.SkuParser.Api/Controllers/CommonParseController.cs (renamed from RhSolutions.SkuParser.Api/Controllers/ProductsController.cs)18
1 files changed, 9 insertions, 9 deletions
diff --git a/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs b/RhSolutions.SkuParser.Api/Controllers/CommonParseController.cs
index 77b277b..c819851 100644
--- a/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs
+++ b/RhSolutions.SkuParser.Api/Controllers/CommonParseController.cs
@@ -1,16 +1,16 @@
using Microsoft.AspNetCore.Mvc;
using RhSolutions.SkuParser.Models;
-using RhSolutions.SkuParser.Services;
+using RhSolutions.SkuParser.Abstractions;
namespace RhSolutions.SkuParser.Controllers;
[ApiController]
[Route("/api/[controller]")]
-public class ProductsController : ControllerBase
+public class CommonParseController : ControllerBase
{
private IServiceProvider _provider;
private Dictionary<Product, double> _result;
- public ProductsController(IServiceProvider provider)
+ public CommonParseController(IServiceProvider provider)
{
_provider = provider;
_result = new();
@@ -25,16 +25,16 @@ public class ProductsController : ControllerBase
foreach (var file in files)
{
ISkuParser parser = _provider.GetRequiredKeyedService<ISkuParser>(file.ContentType);
- IEnumerable<ProductQuantity> productQuantities = parser.ParseProducts(file);
- foreach (ProductQuantity pq in productQuantities)
+ var dict = parser.ParseProducts(file);
+ foreach (var kvp in dict)
{
- if (_result.ContainsKey(pq.Product))
+ if (_result.ContainsKey(kvp.Key))
{
- _result[pq.Product] += pq.Quantity;
+ _result[kvp.Key] += kvp.Value;
}
else
{
- _result.Add(pq.Product, pq.Quantity);
+ _result.Add(kvp.Key, kvp.Value);
}
}
}
@@ -43,6 +43,6 @@ public class ProductsController : ControllerBase
{
return BadRequest(error: $"{ex.Message}\n\n{ex.Source}\n{ex.StackTrace}");
}
- return new JsonResult(_result.Select(x => new { Sku = x.Key.ToString(), Quantity = x.Value }));
+ return new JsonResult(_result.Select(x => new { x.Key.Sku, x.Value }));
}
} \ No newline at end of file