Example #1
0
 /**
  * @ApiDoc(
  *  section="Items",
  *  description="Create a new item",
  *  input="AppBundle\Controller\Form\ItemFormType",
  *  output="AppBundle\Controller\ItemController",
  *  parameters={
  *      {"name"="Request", "dataType"="HTTP request", "required"=true, "description"="The HTTP Request"}
  *     },
  *  statusCodes={
  *       201="Returned when an item has been created",
  *       400="Returned when form is not filled correctly"
  * }
  * )
  */
 public function postItemAction(Request $request)
 {
     $item = new Item();
     // let's just set itemuserid(foreignKey)
     $item->setItemuserid($this->getUserInstance());
     $form = $this->getForm($item);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($item);
         $em->flush();
         // response
         $view = $this->get('raiponce')->getView('Your item has been added!', 201);
         return $this->handleView($view);
     } else {
         throw new HttpException(400, 'the form is not filled correctly');
     }
 }