From 5f3193e0bc1cd873dd852a143d2e85c573d179ed Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Thu, 4 Aug 2022 13:07:22 +0200 Subject: [PATCH] [Update] Add tags and supertags (groups/super_groups) --- src/Controller/Api/RoutingController.php | 52 ++++++++++++++++++++++ src/Controller/Options/SuperTagOptions.php | 14 ++++++ src/Controller/Options/TagOptions.php | 20 +++++++++ src/Controller/Tag/SuperTagController.php | 33 ++++++++++++++ src/Controller/Tag/TagController.php | 47 +++++++++++++++++++ 5 files changed, 166 insertions(+) create mode 100644 src/Controller/Options/SuperTagOptions.php create mode 100644 src/Controller/Options/TagOptions.php create mode 100644 src/Controller/Tag/SuperTagController.php create mode 100644 src/Controller/Tag/TagController.php diff --git a/src/Controller/Api/RoutingController.php b/src/Controller/Api/RoutingController.php index dd1841f..208df12 100644 --- a/src/Controller/Api/RoutingController.php +++ b/src/Controller/Api/RoutingController.php @@ -18,6 +18,8 @@ use Oveleon\ContaoPropstackApiBundle\Controller\Note\NoteController; use Oveleon\ContaoPropstackApiBundle\Controller\SearchInquiry\SearchInquiryController; use Oveleon\ContaoPropstackApiBundle\Controller\Hook\HookController; +use Oveleon\ContaoPropstackApiBundle\Controller\Tag\TagController; +use Oveleon\ContaoPropstackApiBundle\Controller\Tag\SuperTagController; use Oveleon\ContaoPropstackApiBundle\Controller\Task\TaskController; use Oveleon\ContaoPropstackApiBundle\Controller\Team\TeamController; use Oveleon\ContaoPropstackApiBundle\Controller\Unit\UnitController; @@ -278,6 +280,56 @@ public function activityTypes(): JsonResponse throw new ApiMethodDeniedException('The method used is not supported'); } + /** + * Tags + * + * @Route("/tags", name="tags") + */ + public function tags(): JsonResponse + { + $request = $this->requestStack->getCurrentRequest(); + $parameters = $request->query->all(); + + $objTags = new TagController(); + $objTags->setFormat(PropstackController::FORMAT_JSON); + + switch($request->getMethod()) + { + case PropstackController::METHOD_READ: + // Read + return $objTags->read($parameters); + + case PropstackController::METHOD_CREATE: + // Create + return $objTags->create($parameters); + } + + throw new ApiMethodDeniedException('The method used is not supported'); + } + + /** + * Super tags + * + * @Route("/super_tags", name="super_tags") + */ + public function superTags(): JsonResponse + { + $request = $this->requestStack->getCurrentRequest(); + $parameters = $request->query->all(); + + $objTags = new SuperTagController(); + $objTags->setFormat(PropstackController::FORMAT_JSON); + + switch($request->getMethod()) + { + case PropstackController::METHOD_READ: + // Read + return $objTags->read($parameters); + } + + throw new ApiMethodDeniedException('The method used is not supported'); + } + /** * Tasks * diff --git a/src/Controller/Options/SuperTagOptions.php b/src/Controller/Options/SuperTagOptions.php new file mode 100644 index 0000000..eacd612 --- /dev/null +++ b/src/Controller/Options/SuperTagOptions.php @@ -0,0 +1,14 @@ +set(Options::MODE_READ, [ + 'entity', + 'include' + ]); + } +} diff --git a/src/Controller/Options/TagOptions.php b/src/Controller/Options/TagOptions.php new file mode 100644 index 0000000..dab2f4c --- /dev/null +++ b/src/Controller/Options/TagOptions.php @@ -0,0 +1,20 @@ +set(Options::MODE_READ, [ + 'super_group', + 'entity' + ]); + + $this->set(Options::MODE_CREATE, [ + 'super_group_id', + 'entity', + 'name', + ]); + } +} diff --git a/src/Controller/Tag/SuperTagController.php b/src/Controller/Tag/SuperTagController.php new file mode 100644 index 0000000..6f30c64 --- /dev/null +++ b/src/Controller/Tag/SuperTagController.php @@ -0,0 +1,33 @@ + + */ +class SuperTagController extends PropstackController +{ + protected string $route = 'super_groups'; + + /** + * Read super tags + */ + public function read(array $parameters) + { + $this->call( + (new SuperTagOptions(Options::MODE_READ)) + ->validate($parameters), + self::METHOD_READ + ); + + return $this->getResponse(); + } +} diff --git a/src/Controller/Tag/TagController.php b/src/Controller/Tag/TagController.php new file mode 100644 index 0000000..2c063dd --- /dev/null +++ b/src/Controller/Tag/TagController.php @@ -0,0 +1,47 @@ + + */ +class TagController extends PropstackController +{ + protected string $route = 'groups'; + + /** + * Read tags + */ + public function read(array $parameters) + { + $this->call( + (new TagOptions(Options::MODE_READ)) + ->validate($parameters), + self::METHOD_READ + ); + + return $this->getResponse(); + } + + /** + * Create tags + */ + public function create(array $parameters) + { + $this->call( + (new TagOptions(Options::MODE_CREATE)) + ->validate($parameters), + self::METHOD_CREATE + ); + + return $this->getResponse(); + } +}