Skip to content

Instantly share code, notes, and snippets.

@azumamagus
Created March 25, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azumamagus/7dbf9c4c56041928e8f9f3d5e9b18af5 to your computer and use it in GitHub Desktop.
Save azumamagus/7dbf9c4c56041928e8f9f3d5e9b18af5 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: Bruno
* Date: 25/03/2019
* Time: 10:49
*/
namespace App\Controller;
use App\Entidades\Medico;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MedicosController
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @Route("/medicos",methods={"POST"})
*/
public function novo(Request $request) : Response
{
$corpoRequisicao = $request->getContent();
$dadoEmJson = json_decode($corpoRequisicao);
$medico = new Medico();
$medico->crm = $dadoEmJson->crm;
$medico->nome = $dadoEmJson->nome;
$this->entityManager->persist($medico);
$this->entityManager->flush();
return new JsonResponse($medico);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment