-
-
Notifications
You must be signed in to change notification settings - Fork 803
Expand file tree
/
Copy pathCheckInventoryRequestHandler.cs
More file actions
31 lines (27 loc) · 1.03 KB
/
CheckInventoryRequestHandler.cs
File metadata and controls
31 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using AotExample.Contracts.Requests;
using Mocha;
namespace AotExample.OrderService.Handlers;
public sealed class CheckInventoryRequestHandler(
ILogger<CheckInventoryRequestHandler> logger)
: IEventRequestHandler<CheckInventoryRequest, CheckInventoryResponse>
{
public ValueTask<CheckInventoryResponse> HandleAsync(
CheckInventoryRequest request,
CancellationToken cancellationToken)
{
var quantityOnHand = Random.Shared.Next(0, 20);
var isAvailable = quantityOnHand >= request.Quantity;
logger.LogInformation(
"Inventory check for {ProductName}: {QuantityOnHand} on hand, requested {Quantity} — {Result}",
request.ProductName,
quantityOnHand,
request.Quantity,
isAvailable ? "available" : "insufficient");
return new ValueTask<CheckInventoryResponse>(
new CheckInventoryResponse
{
IsAvailable = isAvailable,
QuantityOnHand = quantityOnHand
});
}
}