/** * @Route("/api/v1/authors", name="api_authors") * @param Request $request * * @return JsonResponse */ public function indexAction(Request $request) { $authorName = $request->query->get('fullNameStartsWith'); if (strlen($authorName) < 3) { throw new BadRequestHttpException("At least three letters needed to fetch author list"); } $authors = $this->repository->findWithNameStartingWith($authorName); return new JsonResponse($this->normalizer->normalize($authors, 'json', ['groups' => ['list']])); }
/** * @param int $id * * @return Author|null|object */ private function getAuthorById(int $id) { $author = $this->repository->find($id); if (null === $author) { throw new NotFoundHttpException("Author with id '{$id}' is not found"); } return $author; }