← Back
Editing: ControleApiController.php
<?php namespace App\Controller\Api; use App\Entity\Adresse; use App\Entity\Controle; use App\Service\Control\ControlDenormalizer; use App\Service\Control\ControlPersister; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\Validator\ValidatorInterface; #[Route(path: '/api/controle', name: 'api_controle_')] class ControleApiController extends AbstractApiController { #[Route(path: '/{id}', name: 'get', requirements: ['id' => '\d+'], methods: ['GET'])] public function getAction(Adresse $adresse, ValidatorInterface $validator): JsonResponse { $controle = new Controle(); $controle->setAgent($this->getUser()); $controle->setAdresse($adresse); $controle->setValide(false); $errors = $validator->validate($controle); if ($errors->count() > 0) { return $this->validationErrorResponse($errors); } $this->em->persist($controle); $this->em->flush(); return $this->response($controle, 'show_control'); } #[Route(path: '/patch', name: 'patch', methods: ['PATCH'])] public function patchAction( Request $request, LoggerInterface $logger, ControlDenormalizer $controlDenormalizer, ControlPersister $controlPersister ): JsonResponse { $receivedControl = json_decode($request->getContent(), true); $logger->info(print_r($receivedControl, true)); $control = ($controlDenormalizer)($receivedControl); ($controlPersister)($control, $receivedControl); return $this->response($control, 'show_control'); } }
Save File
Cancel