diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index 10889b03bcd56d24e122496b19284f8c946cd27f..8f7c577b15545f4087102d841fd36a23ebd315b3 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()); } }