taskcancellation #131
@@ -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 item not found or failed to remove.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<Result<Order[]>> GetOrdersByCustomerAsync(long customerId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user