return $this->PersonNotFound();
}
- return $person->getFriendsWithMe();
+ $friends_with_me = $person->getFriendsWithMe();
+
+ return $friends_with_me;
}
/**
$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);
}
curl --request PUT http://localhost:8000/api/person/1/online
curl --request PUT http://localhost:8000/api/person/1/offline
+* Search a user with a keyword:
+curl --request POST http://localhost:8000/api/person/search --data "{ \"keyword\": \"isabelle\"}" --header "Content-Type: application/json"
+
* Show a user with id 1:
curl --request GET http://localhost:8000/api/person/1