/** * @Route("api/v1/books/add") * @param Request $request */ public function addAction(Request $request) { if (!$this->authentication($request)) { $messages = array("message" => "Autentication error, use right api key"); return $this->jsonResponse($messages); } $messages = array(); if ($request->getMethod() === "POST") { $bookParametrBag = $request->request; $book = Book::createBook($bookParametrBag); if (is_array($book)) { $messages = $book; } if (count($messages) === 0) { $entityManager = $this->getDoctrine()->getManager(); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($book); $entityManager->flush(); $messages["message"] = "done"; } else { $messages["message"] = "error"; } } else { $messages["message"] = "error"; $messages["method_error"] = "You should use POST method"; } return $this->jsonResponse($messages); }