Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikus1993 committed Feb 11, 2024
1 parent 000ac29 commit 8694956
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Modules/Basket/Core/Model/Products.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private Products(IReadOnlyList<Product> items)
_items = items;
}

public static Products Empty => new([]);
public static readonly Products Empty = new([]);
public Products AddItem(Product item)
{
var items = new List<Product>(_items);
Expand All @@ -32,7 +32,7 @@ public Products AddItem(Product item)
items[index] = newItem;
}

return [..items];
return new Products(items);
}

public Products AddItems(IEnumerable<Product> items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<UpdateBasketSuccess>> Update(CustomerBasket basket, CancellationToken cancellationToken = default)
Expand Down
20 changes: 18 additions & 2 deletions src/Modules/Warehouse/Core/Model/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
using System.Numerics;

namespace Warehouse.Core.Model;

public class WarehouseItem
public readonly record struct ItemQuantity(int Value) : IAdditionOperators<ItemQuantity, ItemQuantity, ItemQuantity>, ISubtractionOperators<ItemQuantity, ItemQuantity, ItemQuantity>
{
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)
{

}

0 comments on commit 8694956

Please sign in to comment.