src/Controller/Customer/CustomerController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Customer;
  3. use App\Handler\Customer\CrudCustomerHandler;
  4. use Doctrine\Common\Annotations\AnnotationException;
  5. use ReflectionException;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  11. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  12. use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
  13. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  14. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  15. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  16. /**
  17.  * Class CustomerController.
  18.  */
  19. final class CustomerController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/api/customers", name="customer_edit_route", methods={"PUT"})
  23.      *
  24.      * @param Request $request
  25.      * @param CrudCustomerHandler $crudCustomerHandler
  26.      *
  27.      * @return JsonResponse
  28.      *
  29.      * @throws AnnotationException
  30.      * @throws ClientExceptionInterface
  31.      * @throws DecodingExceptionInterface
  32.      * @throws ExceptionInterface
  33.      * @throws RedirectionExceptionInterface
  34.      * @throws ReflectionException
  35.      * @throws ServerExceptionInterface
  36.      * @throws TransportExceptionInterface
  37.      */
  38.     public function editCustomer(Request $requestCrudCustomerHandler $crudCustomerHandler): JsonResponse
  39.     {
  40.         return new JsonResponse($crudCustomerHandler->handlePut(
  41.             $request->get('request') ?: $request->getContent(),
  42.             $request->files->all()
  43.         ));
  44.     }
  45.     /**
  46.      * @Route("/api/customers", name="customer_new_route", methods={"POST"})
  47.      *
  48.      * @param Request $request
  49.      * @param CrudCustomerHandler $crudCustomerHandler
  50.      *
  51.      * @return JsonResponse
  52.      *
  53.      * @throws AnnotationException
  54.      * @throws ClientExceptionInterface
  55.      * @throws DecodingExceptionInterface
  56.      * @throws ExceptionInterface
  57.      * @throws RedirectionExceptionInterface
  58.      * @throws ReflectionException
  59.      * @throws ServerExceptionInterface
  60.      * @throws TransportExceptionInterface
  61.      */
  62.     public function postCustomer(Request $requestCrudCustomerHandler $crudCustomerHandler): JsonResponse
  63.     {
  64.         return new JsonResponse($crudCustomerHandler->handlePost(
  65.             $request->get('request') ?: $request->getContent(),
  66.             $request->files->all()
  67.         ));
  68.     }
  69. }