Commit edcb1979 authored by Mat's avatar Mat
Browse files

createAction pour les 2 entités Info et Lettre

parent 4386b5c1
......@@ -2,14 +2,34 @@
namespace APIBundle\Controller;
use APIBundle\Form\InfoAPIType;
use PotageBundle\Entity\Info;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class InfoAPIController extends MasterAPIController
{
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function createAction(Request $request)
{
$info = new Info();
$form = $this->createForm(InfoAPIType::class, $info);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($info);
$em->flush();
return $this->api($info);
}
return $this->api($form, Response::HTTP_BAD_REQUEST);
}
......
......@@ -2,14 +2,34 @@
namespace APIBundle\Controller;
use APIBundle\Form\LettreAPIType;
use PotageBundle\Entity\Lettre;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class LettreAPIController extends MasterAPIController
{
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function createAction(Request $request)
{
$lettre = new Lettre();
$form = $this->createForm(LettreAPIType::class, $lettre);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($lettre);
$em->flush();
return $this->api($lettre);
}
return $this->api($form, Response::HTTP_BAD_REQUEST);
}
......
......@@ -124,6 +124,13 @@ api_lettre_read:
_controller: APIBundle:LettreAPI:read
methods: [ GET ]
api_lettre_create:
path: /lettre/ajouter
defaults:
_controller: APIBundle:LettreAPI:create
methods: [ POST ]
## CRUD InfoAPI
api_info_read:
......@@ -131,3 +138,10 @@ api_info_read:
defaults:
_controller: APIBundle:InfoAPI:read
methods: [ GET ]
api_info_create:
path: /info/ajouter
defaults:
_controller: APIBundle:InfoAPI:create
methods: [ POST ]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment