X-Git-Url: https://git.piment-noir.org/?p=Project_proches_de_moi-server.git;a=blobdiff_plain;f=src%2FController%2FPersonController.php;fp=src%2FController%2FPersonController.php;h=6b4120545ec9196498d354910457e2de92407f97;hp=b34bb53d6f60aea5e094fee951714ad11962e57f;hb=80ec112fadb2fb94341049775f12fd5496662129;hpb=19b09998f57d37c571830bed32c1090a424b91cb diff --git a/src/Controller/PersonController.php b/src/Controller/PersonController.php index b34bb53..6b41205 100644 --- a/src/Controller/PersonController.php +++ b/src/Controller/PersonController.php @@ -342,7 +342,9 @@ class PersonController extends FOSRestController return $this->PersonNotFound(); } - return $person->getFriendsWithMe(); + $friends_with_me = $person->getFriendsWithMe(); + + return $friends_with_me; } /** @@ -410,6 +412,30 @@ class PersonController extends FOSRestController $em->flush(); } + /** + * @Rest\Post( + * path = "/api/person/search", + * name = "search_person" + * ) + * @Rest\View() + */ + public function searchPerson(Request $request) + { + $em = $this->getDoctrine()->getManager(); + $query = $em->createQuery("SELECT DISTINCT p FROM App\Entity\Person p WHERE + p.firstname LIKE :keyword or + p.lastname LIKE :keyword or + p.email LIKE :keyword"); + $query->setParameter('keyword', '%'.$request->get('keyword').'%'); + $persons = $query->getResult(); + + if (empty($persons)) { + return $this->PersonNotFound(); + } + + return $persons; + } + private function PersonNotFound() { return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND); }