Added CancelOrder action with output handling for order cancellation. Introduced CancelOrderOutput enum to represent cancellation states. Refactored ShopPolicy to simplify user checks in viewPickupTimeslots. Updated tests to reflect changes in policy behavior.
38 lines
933 B
PHP
38 lines
933 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Actions\Orders;
|
|
|
|
use App\Contracts\Action;
|
|
use App\Contracts\ActionInput;
|
|
use Domain\Services\OrderService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Action<\App\Cqs\Actions\Orders\CancelOrderInput, \App\Cqs\Actions\Orders\CancelOrderOutput>
|
|
*/
|
|
final class CancelOrder implements Action
|
|
{
|
|
public function __construct(
|
|
private readonly OrderService $orderService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Cqs\Actions\Orders\CancelOrderInput $input
|
|
*/
|
|
#[\Override]
|
|
public function __invoke(ActionInput $input): CancelOrderOutput
|
|
{
|
|
Assert::isInstanceOf($input, CancelOrderInput::class);
|
|
|
|
try {
|
|
$this->orderService->cancelOrder($input->order->getId());
|
|
} catch (\DomainException) {
|
|
return CancelOrderOutput::NOT_FOUND;
|
|
}
|
|
|
|
return CancelOrderOutput::CANCELLED;
|
|
}
|
|
}
|