aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2025-01-14 14:01:01 +0000
committerSerghei Cebotari <serghei@cebotari.ru>2025-01-14 14:01:01 +0000
commita542bfb7f4ceee8b49cf8fcadf64ffb72cc97da5 (patch)
tree5e9563638eb09a4c3a1c717a6f238139fc66dc53 /RhSolutions.SkuParser.Api/Controllers/ProductsController.cs
parente2ac0c46c1a1085ab7e7597e463e73f371ce2791 (diff)
Common Parsing Method
Diffstat (limited to 'RhSolutions.SkuParser.Api/Controllers/ProductsController.cs')
-rw-r--r--RhSolutions.SkuParser.Api/Controllers/ProductsController.cs48
1 files changed, 0 insertions, 48 deletions
diff --git a/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs b/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs
deleted file mode 100644
index 77b277b..0000000
--- a/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-using RhSolutions.SkuParser.Models;
-using RhSolutions.SkuParser.Services;
-
-namespace RhSolutions.SkuParser.Controllers;
-
-[ApiController]
-[Route("/api/[controller]")]
-public class ProductsController : ControllerBase
-{
- private IServiceProvider _provider;
- private Dictionary<Product, double> _result;
- public ProductsController(IServiceProvider provider)
- {
- _provider = provider;
- _result = new();
- }
-
- [HttpPost]
- public IActionResult PostFiles()
- {
- IFormFileCollection files = Request.Form.Files;
- try
- {
- foreach (var file in files)
- {
- ISkuParser parser = _provider.GetRequiredKeyedService<ISkuParser>(file.ContentType);
- IEnumerable<ProductQuantity> productQuantities = parser.ParseProducts(file);
- foreach (ProductQuantity pq in productQuantities)
- {
- if (_result.ContainsKey(pq.Product))
- {
- _result[pq.Product] += pq.Quantity;
- }
- else
- {
- _result.Add(pq.Product, pq.Quantity);
- }
- }
- }
- }
- catch (Exception ex)
- {
- 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 }));
- }
-} \ No newline at end of file