From a9f259d74c60aa89d97b2827844380b347d84255 Mon Sep 17 00:00:00 2001 From: Romain Lebbadi-Breteau <romain@lebbadi.fr> Date: Sun, 5 Feb 2023 06:44:29 -0500 Subject: [PATCH] I transformed a bug into a feature. Once you learn how, you'll never forget it --- src/Controller/ApiController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index 10889b0..8f7c577 100644 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -16,6 +16,7 @@ use App\Entity\Transaction; use App\Entity\User; use App\Service\CategoryService; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; @@ -87,6 +88,9 @@ class ApiController extends AbstractController */ $user = $this->getUser(); try { + /** + * @var Transaction + */ $transaction = $this->serializer->deserialize($request->getContent(), Transaction::class, "json", [DateTimeNormalizer::FORMAT_KEY => "Y-m-d"]); } catch (\Exception $error) { return new Response($error, 400); @@ -95,7 +99,7 @@ class ApiController extends AbstractController $user->addTransaction($transaction); $entityManager->persist($transaction); $entityManager->flush(); - return new Response(); + return new Response($this->serializer->serialize($transaction, "json"), 200, ["Content-Type" => "application/json"]); } #[Route('/api/transaction/{id}', name: 'api_transaction_delete', methods: ['DELETE'])] @@ -126,6 +130,6 @@ class ApiController extends AbstractController $entityManager->flush(); - return new Response(); + return new JsonResponse($transaction->getCategory()); } } -- GitLab