-
-
Save azumamagus/7dbf9c4c56041928e8f9f3d5e9b18af5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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