89 lines
3.6 KiB
C#
89 lines
3.6 KiB
C#
using Kitchen.Service.Contracts.Contracts;
|
|
using Kitchen.Service.Contracts.Requests;
|
|
using Kitchen.Service.Contracts.Responses;
|
|
|
|
namespace Kitchen.Service.Application.Ports;
|
|
|
|
public sealed class DefaultKitchenWorkflowPort : IKitchenWorkflowPort
|
|
{
|
|
public Task<GetKitchenBoardResponse> GetKitchenBoardAsync(GetKitchenBoardRequest request, CancellationToken cancellationToken)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var lanes = new[]
|
|
{
|
|
new KitchenBoardLaneContract(
|
|
"queued",
|
|
new[]
|
|
{
|
|
new KitchenBoardItemContract("WK-1001", "CO-1001", "KT-1001", "T-08", "hot-line", "Queued", 3, null, 12),
|
|
new KitchenBoardItemContract("WK-1002", "CO-1003", "KT-1002", "T-12", "expedite", "Queued", 2, null, 8)
|
|
}),
|
|
new KitchenBoardLaneContract(
|
|
"preparing",
|
|
new[]
|
|
{
|
|
new KitchenBoardItemContract("WK-1003", "CO-1002", "KT-1003", "T-15", "grill", "Preparing", 4, "chef-maya", 5)
|
|
}),
|
|
new KitchenBoardLaneContract(
|
|
"ready",
|
|
new[]
|
|
{
|
|
new KitchenBoardItemContract("WK-1004", "CO-0999", "KT-0999", "T-21", "pickup", "ReadyForPickup", 1, "expo-noah", 0)
|
|
})
|
|
};
|
|
|
|
return Task.FromResult(new GetKitchenBoardResponse(
|
|
request.ContextId,
|
|
"Kitchen board shows queued, preparing, and ready lanes for the current service context.",
|
|
lanes,
|
|
new[] { "hot-line", "grill", "salad", "pickup", "expedite" }));
|
|
}
|
|
|
|
public Task<ClaimKitchenWorkItemResponse> ClaimKitchenWorkItemAsync(ClaimKitchenWorkItemRequest request, CancellationToken cancellationToken)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var claimed = !string.IsNullOrWhiteSpace(request.ContextId) &&
|
|
!string.IsNullOrWhiteSpace(request.WorkItemId) &&
|
|
!string.IsNullOrWhiteSpace(request.ClaimedBy);
|
|
|
|
return Task.FromResult(new ClaimKitchenWorkItemResponse(
|
|
request.ContextId,
|
|
request.WorkItemId,
|
|
claimed,
|
|
request.ClaimedBy,
|
|
claimed
|
|
? $"Work item {request.WorkItemId} claimed by {request.ClaimedBy}."
|
|
: "Kitchen work-item claim is incomplete."));
|
|
}
|
|
|
|
public Task<UpdateKitchenPriorityResponse> UpdateKitchenPriorityAsync(UpdateKitchenPriorityRequest request, CancellationToken cancellationToken)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var priority = Math.Max(1, request.Priority);
|
|
return Task.FromResult(new UpdateKitchenPriorityResponse(
|
|
request.ContextId,
|
|
request.WorkItemId,
|
|
priority,
|
|
$"Priority for {request.WorkItemId} updated to {priority} by {request.RequestedBy}."));
|
|
}
|
|
|
|
public Task<TransitionKitchenOrderStateResponse> TransitionKitchenOrderStateAsync(TransitionKitchenOrderStateRequest request, CancellationToken cancellationToken)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var previous = "Queued";
|
|
var allowed = request.TargetState is "Preparing" or "ReadyForPickup" or "Canceled" or "Plated";
|
|
|
|
return Task.FromResult(new TransitionKitchenOrderStateResponse(
|
|
request.OrderId,
|
|
request.TicketId,
|
|
previous,
|
|
allowed ? request.TargetState : previous,
|
|
allowed,
|
|
allowed ? null : "Target state is not allowed by kitchen-service policy."));
|
|
}
|
|
}
|