diff --git a/src/Modules/Basket/Core/Model/Products.cs b/src/Modules/Basket/Core/Model/Products.cs index e6a0c54..c214bda 100644 --- a/src/Modules/Basket/Core/Model/Products.cs +++ b/src/Modules/Basket/Core/Model/Products.cs @@ -16,7 +16,7 @@ private Products(IReadOnlyList items) _items = items; } - public static Products Empty => new([]); + public static readonly Products Empty = new([]); public Products AddItem(Product item) { var items = new List(_items); @@ -32,7 +32,7 @@ public Products AddItem(Product item) items[index] = newItem; } - return [..items]; + return new Products(items); } public Products AddItems(IEnumerable items) diff --git a/src/Modules/Basket/Infrastructure/Repositories/RedisCustomerBasketRepository.cs b/src/Modules/Basket/Infrastructure/Repositories/RedisCustomerBasketRepository.cs index 33e6e54..fc54c90 100644 --- a/src/Modules/Basket/Infrastructure/Repositories/RedisCustomerBasketRepository.cs +++ b/src/Modules/Basket/Infrastructure/Repositories/RedisCustomerBasketRepository.cs @@ -32,7 +32,7 @@ public RedisCustomerBasketRepository(IConnectionMultiplexer connectionMultiplexe var items = model.Items.Select(static item => new Product(new ItemId(item.ItemId), new ItemQuantity(item.Quantity))); - return CustomerBasket.Empty(customerId).AddItems(items); + return CustomerBasket.Active(customerId, [..items]); } public async Task> Update(CustomerBasket basket, CancellationToken cancellationToken = default) diff --git a/src/Modules/Warehouse/Core/Model/Entity.cs b/src/Modules/Warehouse/Core/Model/Entity.cs index 94d0281..48d266c 100644 --- a/src/Modules/Warehouse/Core/Model/Entity.cs +++ b/src/Modules/Warehouse/Core/Model/Entity.cs @@ -1,6 +1,22 @@ +using System.Numerics; + namespace Warehouse.Core.Model; -public class WarehouseItem +public readonly record struct ItemQuantity(int Value) : IAdditionOperators, ISubtractionOperators +{ + public static readonly ItemQuantity Zero = new(0); + public static ItemQuantity operator +(ItemQuantity left, ItemQuantity right) + { + return new ItemQuantity(left.Value + right.Value); + } + + public static ItemQuantity operator -(ItemQuantity left, ItemQuantity right) + { + var res = left.Value - right.Value; + return res < 0 ? Zero : new ItemQuantity(res); + } +} + +public sealed record WarehouseItem(ProductId ProductId, ItemQuantity Quantity) { - } \ No newline at end of file