46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Aggregate\AcceptOrderCommand;
|
|
use App\Contract\OrderDto;
|
|
use App\Exception\ClientNotExistsException;
|
|
use App\Service\ClientService;
|
|
use App\Service\OrderService;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
|
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
#[AsController]
|
|
#[Route(path: '/orders', name: 'orders_')]
|
|
readonly class OrderController
|
|
{
|
|
public function __construct(
|
|
private ClientService $clientService,
|
|
private OrderService $orderService,
|
|
) {
|
|
|
|
}
|
|
|
|
#[Route(name: 'accept', methods: ['POST'])]
|
|
public function accept(#[MapRequestPayload] OrderDto $orderDto): Response
|
|
{
|
|
try {
|
|
$command = new AcceptOrderCommand(
|
|
order: $orderDto,
|
|
client: $this->clientService->getClient($orderDto->getClientId()),
|
|
);
|
|
|
|
$this->orderService->acceptOrder($command);
|
|
|
|
return new Response();
|
|
} catch (ClientNotExistsException) {
|
|
return new Response(status: Response::HTTP_UNPROCESSABLE_ENTITY);
|
|
}
|
|
}
|
|
|
|
}
|