Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db6c77ce6a | |||
| 516062ed5d | |||
| 16832ec214 |
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user