Compare commits

...

2 Commits

Author SHA1 Message Date
Khwezi Mngoma 516062ed5d Refactored order item retrieval error message
continuous-integration/drone/pr Build is passing
2026-06-15 12:08:19 +02:00
Khwezi Mngoma 16832ec214 Added GetOrderItems to OrderService 2026-06-15 12:06:33 +02:00
@@ -203,6 +203,26 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
} }
} }
public async ValueTask<Result<OrderItem[]>> GetOrderItemsAsync(long orderId, CancellationToken cancellationToken = default)
{
try
{
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var orderItems = await context.OrderItems
.Where(o => o.OrderId == orderId)
.ToListAsync(cancellationToken);
return orderItems.Count > 0
? Result.Ok(orderItems.Select(i => i.ToModel()).ToArray())
: Result.Fail<OrderItem[]>($"Order items not found for order ID {orderId}");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
public async ValueTask<Result<Order[]>> GetOrdersByCustomerAsync(long customerId, CancellationToken cancellationToken = default) public async ValueTask<Result<Order[]>> GetOrdersByCustomerAsync(long customerId, CancellationToken cancellationToken = default)
{ {
try try