This commit is contained in:
2026-03-11 21:48:59 +03:00
parent 980f656a0a
commit 02ad7d83ef
365 changed files with 1 additions and 782 deletions

View 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);
}
}
}