viewHandler = $viewHandler; $this->repository = $repository; } /** * Fetch all existing tags * * @SWG\Response( * response=200, * description="Returns the collection of all existing tags as string array", * @SWG\Schema( * type="array", * @SWG\Items(type="string") * ) * ) * * @Rest\QueryParam(name="name", strict=true, nullable=true, description="Search term to filter tag list") * * @ApiSecurity(name="apiUser") * @ApiSecurity(name="apiToken") */ public function cgetAction(ParamFetcherInterface $paramFetcher): Response { $filter = $paramFetcher->get('name'); $data = $this->repository->findAllTagNames($filter); $view = new View($data, 200); $view->getContext()->setGroups(self::GROUPS_COLLECTION); return $this->viewHandler->handle($view); } /** * Creates a new tag * * @SWG\Post( * description="Creates a new tag and returns it afterwards", * @SWG\Response( * response=200, * description="Returns the new created tag", * @SWG\Schema(ref="#/definitions/TagEntity"), * ) * ) * @SWG\Parameter( * name="body", * in="body", * required=true, * @SWG\Schema(ref="#/definitions/TagEditForm") * ) * * @ApiSecurity(name="apiUser") * @ApiSecurity(name="apiToken") */ public function postAction(Request $request): Response { if (!$this->isGranted('manage_tag')) { throw new AccessDeniedHttpException('User cannot create tags'); } $tag = new Tag(); $form = $this->createForm(TagApiEditForm::class, $tag); $form->submit($request->request->all()); if ($form->isValid()) { $this->repository->saveTag($tag); $view = new View($tag, 200); $view->getContext()->setGroups(self::GROUPS_ENTITY); return $this->viewHandler->handle($view); } $view = new View($form); $view->getContext()->setGroups(self::GROUPS_FORM); return $this->viewHandler->handle($view); } /** * Delete a tag * * @SWG\Delete( * @SWG\Response( * response=204, * description="HTTP code 204 for a successful delete" * ), * ) * @SWG\Parameter( * name="id", * in="path", * type="integer", * description="Tag ID to delete", * required=true, * ) * * @Security("is_granted('delete_tag')") * * @ApiSecurity(name="apiUser") * @ApiSecurity(name="apiToken") */ public function deleteAction(int $id): Response { $tag = $this->repository->find($id); if (null === $tag) { throw new NotFoundException(); } $this->repository->deleteTag($tag); $view = new View(null, Response::HTTP_NO_CONTENT); return $this->viewHandler->handle($view); } }