-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: upgrade bmb.domain.core package
- Loading branch information
1 parent
edb9c37
commit b705fc8
Showing
55 changed files
with
662 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="Bmb.Orders.Domain.Test" /> | ||
<InternalsVisibleTo Include="AutoFixture.Xunit2" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Application" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Api.Test" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Controllers.Test" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Application.Test" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Persistence.Test" /> | ||
<InternalsVisibleTo Include="Bmb.Payment.TechChallenge.ByteMeBurger.Persistence.Test" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Persistence.Test" /> | ||
<InternalsVisibleTo Include="FIAP.TechChallenge.ByteMeBurger.Persistence.Test" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bmb.Domain.Core" Version="0.0.17" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.ObjectModel; | ||
using Bmb.Orders.Domain.Entities; | ||
|
||
namespace Bmb.Orders.Domain.Contracts; | ||
|
||
public interface IOrderRepository | ||
{ | ||
Task<Order> CreateAsync(Order order); | ||
|
||
Task<ReadOnlyCollection<Order>> GetAllAsync(); | ||
|
||
Task<Order?> GetAsync(Guid orderId); | ||
|
||
Task<bool> UpdateOrderStatusAsync(Order order); | ||
|
||
Task<bool> UpdateOrderPaymentAsync(Order order); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Bmb.Orders.Domain/Contracts/IOrderTrackingCodeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Bmb.Orders.Domain.ValueObjects; | ||
|
||
namespace Bmb.Orders.Domain.Contracts; | ||
|
||
public interface IOrderTrackingCodeService | ||
{ | ||
Task<OrderTrackingCode> GetNextAsync(); | ||
|
||
OrderTrackingCode GetNext(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
using Bmb.Domain.Core.Base; | ||
using Bmb.Domain.Core.Entities; | ||
using Bmb.Domain.Core.ValueObjects; | ||
using OrderTrackingCode = Bmb.Orders.Domain.ValueObjects.OrderTrackingCode; | ||
|
||
namespace Bmb.Orders.Domain.Entities; | ||
|
||
public class Order : Entity<Guid>, IAggregateRoot | ||
{ | ||
private List<OrderItem> _orderItems = Array.Empty<OrderItem>().ToList(); | ||
|
||
public Bmb.Domain.Core.Entities.Customer? Customer { get; private set; } | ||
|
||
public OrderTrackingCode TrackingCode { get; set; } | ||
|
||
public OrderStatus Status { get; private set; } = OrderStatus.PaymentPending; | ||
|
||
public IReadOnlyList<OrderItem> OrderItems => _orderItems.AsReadOnly(); | ||
|
||
public decimal Total => _orderItems.Sum(o => o.UnitPrice * o.Quantity); | ||
|
||
public PaymentId? PaymentId { get; set; } | ||
|
||
public Order() | ||
Check warning on line 24 in src/Bmb.Orders.Domain/Entities/Order.cs GitHub Actions / build
|
||
: base(Guid.NewGuid()) | ||
{ | ||
Created = DateTime.UtcNow; | ||
} | ||
|
||
internal Order(Guid customerId) | ||
: this(Guid.NewGuid(), new Bmb.Domain.Core.Entities.Customer(customerId)) | ||
{ | ||
Created = DateTime.UtcNow; | ||
} | ||
|
||
internal Order(Bmb.Domain.Core.Entities.Customer customer) | ||
Check warning on line 36 in src/Bmb.Orders.Domain/Entities/Order.cs GitHub Actions / build
|
||
: base(Guid.NewGuid()) | ||
{ | ||
Customer = customer; | ||
Created = DateTime.UtcNow; | ||
} | ||
|
||
internal Order(Guid id, Bmb.Domain.Core.Entities.Customer customer) | ||
Check warning on line 43 in src/Bmb.Orders.Domain/Entities/Order.cs GitHub Actions / build
|
||
: base(id) | ||
{ | ||
Customer = customer; | ||
Created = DateTime.UtcNow; | ||
} | ||
|
||
public Order(Guid id, Bmb.Domain.Core.Entities.Customer? customer, OrderStatus status, OrderTrackingCode trackingCode, DateTime created, | ||
DateTime? updated) | ||
: base(id) | ||
{ | ||
Customer = customer; | ||
Status = status; | ||
TrackingCode = trackingCode; | ||
Created = created; | ||
Updated = updated; | ||
} | ||
|
||
public Order(Bmb.Domain.Core.Entities.Customer? customer, OrderTrackingCode trackingCode, Dictionary<Product, int> selectedProducts) | ||
: base(Guid.NewGuid()) | ||
{ | ||
Customer = customer; | ||
TrackingCode = trackingCode; | ||
Created = DateTime.UtcNow; | ||
|
||
if (selectedProducts.Count == 0) | ||
{ | ||
throw new DomainException("An Order must have at least one item"); | ||
} | ||
|
||
foreach (var (product, quantity) in selectedProducts) | ||
{ | ||
AddOrderItem(product.Id, product.Name, product.Price, quantity); | ||
} | ||
} | ||
|
||
public void AddOrderItem(Guid productId, string productName, decimal unitPrice, int quantity) | ||
{ | ||
if (Status == OrderStatus.PaymentPending) | ||
_orderItems.Add(new OrderItem(Id, productId, productName, unitPrice, quantity)); | ||
else | ||
throw new DomainException( | ||
$"Cannot add items to an Order with status {Status}. Items can only be added when the status is PaymentPending."); | ||
} | ||
|
||
public void LoadItems(Guid productId, string productName, decimal unitPrice, int quantity) | ||
{ | ||
_orderItems.Add(new OrderItem(Id, productId, productName, unitPrice, quantity)); | ||
} | ||
|
||
public void SetPayment(PaymentId paymentId) | ||
{ | ||
if (PaymentId is not null) | ||
{ | ||
throw new DomainException("Order already has a payment intent."); | ||
} | ||
|
||
PaymentId = paymentId; | ||
Update(); | ||
} | ||
|
||
public void SetCustomer(Bmb.Domain.Core.Entities.Customer customer) | ||
{ | ||
Customer = customer; | ||
} | ||
|
||
public void ConfirmPayment() | ||
{ | ||
if (Status != OrderStatus.PaymentPending) | ||
throw new DomainException($"Payment cannot be confirmed because of order status '{Status}'."); | ||
|
||
Status = OrderStatus.Received; | ||
Update(); | ||
} | ||
|
||
public void InitiatePrepare() | ||
{ | ||
if (Status != OrderStatus.Received) | ||
throw new DomainException("Cannot start preparing if order isn't received."); | ||
|
||
Status = OrderStatus.InPreparation; | ||
Update(); | ||
} | ||
|
||
public void FinishPreparing() | ||
{ | ||
if (Status != OrderStatus.InPreparation) | ||
throw new DomainException("Cannot Finish preparing order if it's not In Preparation yet."); | ||
|
||
Status = OrderStatus.Ready; | ||
Update(); | ||
} | ||
|
||
public void DeliverOrder() | ||
{ | ||
if (Status != OrderStatus.Ready) | ||
throw new DomainException("Cannot Deliver order if it's not Ready yet."); | ||
|
||
Status = OrderStatus.Completed; | ||
Update(); | ||
} | ||
|
||
public void SetTrackingCode(OrderTrackingCode code) | ||
{ | ||
if (Status != OrderStatus.PaymentPending) | ||
throw new DomainException("Cannot set status code for an existing Order."); | ||
|
||
TrackingCode = code; | ||
} | ||
|
||
private void Update() => Updated = DateTime.UtcNow; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Bmb.Domain.Core.Base; | ||
|
||
namespace Bmb.Orders.Domain.Entities; | ||
|
||
public class OrderItem : Entity<Guid> | ||
{ | ||
public OrderItem() | ||
{ | ||
} | ||
|
||
public OrderItem(Guid orderId, Guid productId, string productName, decimal unitPrice, int quantity) | ||
: base(Guid.NewGuid()) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(productName); | ||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(unitPrice); | ||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(quantity); | ||
|
||
if (Guid.Empty == orderId) | ||
throw new ArgumentException("Invalid OrderId", nameof(orderId)); | ||
if (Guid.Empty == productId) | ||
throw new ArgumentException("Invalid ProductId", nameof(productId)); | ||
|
||
OrderId = orderId; | ||
ProductId = productId; | ||
ProductName = productName; | ||
UnitPrice = unitPrice; | ||
Quantity = quantity; | ||
} | ||
|
||
public Guid OrderId { get; private set; } | ||
|
||
public Guid ProductId { get; private set; } | ||
|
||
public string ProductName { get; private set; } = string.Empty; | ||
|
||
public decimal UnitPrice { get; private set; } | ||
|
||
public int Quantity { get; private set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Bmb.Orders.Domain.ValueObjects; | ||
|
||
public record OrderTrackingCode | ||
{ | ||
public string Value { get; } | ||
|
||
public OrderTrackingCode(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
throw new ArgumentException("Order tracking code cannot be null or empty.", nameof(value)); | ||
} | ||
|
||
Value = value; | ||
} | ||
|
||
public static implicit operator OrderTrackingCode(string code) => new (code); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Bmb.Orders.Domain.ValueObjects; | ||
|
||
public record SelectedProduct(Guid ProductId, int Quantity); |
3 changes: 2 additions & 1 deletion
3
src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/OrdersController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.