-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathUpdateOrderCommandHandler.php
More file actions
37 lines (29 loc) · 1.11 KB
/
UpdateOrderCommandHandler.php
File metadata and controls
37 lines (29 loc) · 1.11 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
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace Acme\Application\UseCase\Command\Order\UpdateOrder;
use Acme\Domain\Order\Repository\OrderRepositoryInterface;
use Acme\Domain\Shared\Query\Exception\NotFoundException;
use Acme\Domain\Shared\ValueObject\DateTime;
use Acme\Infrastructure\Shared\Bus\Command\CommandHandlerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class UpdateOrderCommandHandler implements CommandHandlerInterface
{
private OrderRepositoryInterface $orderStore;
public function __construct(OrderRepositoryInterface $orderStore)
{
$this->orderStore = $orderStore;
}
public function __invoke(UpdateOrderCommand $command)
{
try {
$order = $this->orderStore->find($command->getUuid());
} catch (NotFoundException $e) {
throw new NotFoundHttpException($e->getMessage());
}
$order->setNumber($command->getNumber());
$order->setState($command->getState());
$order->setTotal($command->getTotal());
$order->setUpdatedAt(DateTime::now());
$this->orderStore->store($order);
}
}