Fix csv parsing
This commit is contained in:
parent
c1b7be71c9
commit
5439fcfb75
@ -1,30 +0,0 @@
|
|||||||
using CsvHelper.Configuration.Attributes;
|
|
||||||
|
|
||||||
namespace RhSolutions.SkuParser.Models;
|
|
||||||
|
|
||||||
public class ProductQuantity
|
|
||||||
{
|
|
||||||
[Index(0)]
|
|
||||||
public required Product Product { get; set; }
|
|
||||||
[Index(1)]
|
|
||||||
public required double Quantity { get; set; }
|
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
|
||||||
{
|
|
||||||
if (obj == null || GetType() != obj.GetType())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ProductQuantity other = (ProductQuantity)obj;
|
|
||||||
return Product == other.Product &&
|
|
||||||
Quantity == other.Quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
HashCode hash = new();
|
|
||||||
hash.Add(Product);
|
|
||||||
hash.Add(Quantity);
|
|
||||||
return hash.ToHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
11
RhSolutions.SkuParser.Api/Models/SkuQuantity.cs
Normal file
11
RhSolutions.SkuParser.Api/Models/SkuQuantity.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using CsvHelper.Configuration.Attributes;
|
||||||
|
|
||||||
|
namespace RhSolutions.SkuParser.Models;
|
||||||
|
|
||||||
|
public record SkuQuantity
|
||||||
|
{
|
||||||
|
[Index(0)]
|
||||||
|
public required string Sku { get; set; }
|
||||||
|
[Index(1)]
|
||||||
|
public required double Quantity { get; set; }
|
||||||
|
}
|
@ -20,7 +20,7 @@ public class CommonCsvParser : ISkuParser
|
|||||||
};
|
};
|
||||||
using CsvReader csvReader = new(reader, config);
|
using CsvReader csvReader = new(reader, config);
|
||||||
|
|
||||||
return csvReader.GetRecords<ProductQuantity>()
|
return csvReader.GetRecords<SkuQuantity>()
|
||||||
.ToDictionary(pq => new Product() { Sku = pq.Product.Sku }, pq => pq.Quantity);
|
.ToDictionary(pq => new Product() { Sku = pq.Sku }, pq => pq.Quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user