WIP
This commit is contained in:
37
backend/src/app/Handlers/OrderHandler.php
Executable file
37
backend/src/app/Handlers/OrderHandler.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handlers;
|
||||
|
||||
use App\Exceptions\OrderValidationFailedException;
|
||||
use App\Services\OrderCreateService;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Openguru\OpenCartFramework\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class OrderHandler
|
||||
{
|
||||
private OrderCreateService $orderCreateService;
|
||||
|
||||
public function __construct(OrderCreateService $orderCreateService)
|
||||
{
|
||||
$this->orderCreateService = $orderCreateService;
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$order = $this->orderCreateService->create($request->json(), [
|
||||
'ip' => $request->getClientIp(),
|
||||
'user_agent' => $request->getUserAgent(),
|
||||
]);
|
||||
|
||||
return new JsonResponse([
|
||||
'data' => $order,
|
||||
], Response::HTTP_CREATED);
|
||||
} catch (OrderValidationFailedException $exception) {
|
||||
return new JsonResponse([
|
||||
'data' => $exception->getErrorBag()->firstOfAll(),
|
||||
], Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user