use App\Entity\Person;
use App\Entity\Localisation;
use \Datetime;
+use \NotNull;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\View\ViewHandler;
use FOS\RestBundle\View\View;
+use FOS\RestBundle\Request\ParamFetcherInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$em->persist($person);
$em->flush();
- return $this->view($person, Response::HTTP_CREATED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]);
+ return $this->view($person, Response::HTTP_CREATED,
+ ['Location' => $this->generateUrl('show_person',
+ ['id' => $person->getId(),
+ UrlGeneratorInterface::ABSOLUTE_URL])]);
}
/**
$em->merge($person);
$em->flush();
- return $this->view($person, Response::HTTP_CREATED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]);
+ return $this->view($person, Response::HTTP_CREATED,
+ ['Location' => $this->generateUrl('show_person',
+ ['id' => $person->getId(),
+ UrlGeneratorInterface::ABSOLUTE_URL])]);
}
/**
if ($request->get('password') != $person->getPassword()) {
return $this->PersonWrongPassword();
} else {
- return $this->view($person, Response::HTTP_ACCEPTED, ['Location' => $this->generateUrl('show_person', ['id' => $person->getId(), UrlGeneratorInterface::ABSOLUTE_URL])]);
+ return $this->view($person, Response::HTTP_ACCEPTED,
+ ['Location' => $this->generateUrl('show_person',
+ ['id' => $person->getId(),
+ UrlGeneratorInterface::ABSOLUTE_URL])]);
}
}
}
private function getLastLocalisation($em, $id) {
- $query = $em->createQuery("SELECT l1 FROM App\Entity\Localisation l1 WHERE l1.person = :person and l1.timestamp = (SELECT MAX(l2.timestamp) FROM App\Entity\Localisation l2 WHERE l2.person = l1.person)");
+ $query = $em->createQuery("SELECT l1 FROM App\Entity\Localisation l1
+ WHERE l1.person = :person and l1.timestamp =
+ (SELECT MAX(l2.timestamp) FROM App\Entity\Localisation l2
+ WHERE l2.person = l1.person)");
$query->setParameter('person', $id);
$result = $query->getResult();
if (!empty($result)) {
return $this->PersonNotFound();
}
- return $person->getFriendsWithMe();
+ $friends_with_me = $person->getFriendsWithMe();
+
+ return $friends_with_me;
}
/**
$em->flush();
}
+ /**
+ * @Rest\Get(
+ * path = "/api/person/search",
+ * name = "search_person"
+ * )
+ * @Rest\QueryParam(name="keyword")
+ * @Rest\View()
+ */
+ public function searchPerson(ParamFetcherInterface $paramFetcher)
+ {
+ $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', '%'.$paramFetcher->get('keyword').'%');
+ $persons = $query->getResult();
+
+ if (empty($persons)) {
+ return $this->PersonsNotFound();
+ }
+
+ return $persons;
+ }
+
private function PersonNotFound() {
return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
}