commit 4b5e4b40cf2b64419de0067ed0597fc80cf2fda0
parent 9f5fbd9e1e2288e122fdda7f51dffd467d9be86c
Author: Felicitus <felicitus@felicitus.org>
Date: Fri, 24 Jul 2015 19:07:23 +0200
Refactored footprint category controller to a single, global category controller which can be used by any entity which uses categories
Diffstat:
4 files changed, 112 insertions(+), 51 deletions(-)
diff --git a/app/config/config.yml b/app/config/config.yml
@@ -183,7 +183,6 @@ services:
"hydra:title": "A custom operation"
"returns": "xmls:string"
-
resource.footprint_image:
parent: "api.resource"
arguments: [ "PartKeepr\FootprintBundle\Entity\FootprintImage" ]
@@ -258,7 +257,7 @@ services:
- "@resource.footprint_category" # Resource
- [ "PUT" ] # Methods
- "/footprint_categories/{id}/move" # Path
- - "PartKeeprFootprintBundle:FootprintCategory:move" # Controller
+ - "PartKeeprCategoryBundle:Category:move" # Controller
- "FootprintCategoryMove" # Route name
- # Context (will be present in Hydra documentation)
"@type": "hydra:Operation"
@@ -419,7 +418,69 @@ services:
arguments:
- { groups: [ "default" ] }
+# ######################## Storage Location Categories######################################
+ resource.storage_location:
+ parent: "api.resource"
+ arguments: [ "PartKeepr\StorageLocationBundle\Entity\StorageLocation" ]
+ tags: [ { name: "api.resource" } ]
+ calls:
+ - method: "initFilters"
+ arguments: [ [ "@doctrine_reflection_service.search_filter" ] ]
+ - method: "initNormalizationContext"
+ arguments: [ { groups: [ "default" ] } ]
+ - method: "initDenormalizationContext"
+ arguments:
+ - { groups: [ "default" ] }
+
+# ######################## Storage Location Categories######################################
+
+ resource.storage_location_category.item_operation.move:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments:
+ - "@resource.storage_location_category" # Resource
+ - [ "PUT" ] # Methods
+ - "/storage_location_categories/{id}/move" # Path
+ - "PartKeeprCategoryBundle:Category:move" # Controller
+ - "StorageLocationCategoryMove" # Route name
+ - # Context (will be present in Hydra documentation)
+ "@type": "hydra:Operation"
+ "hydra:title": "A custom operation"
+ "returns": "xmls:string"
+
+ resource.storage_location_category.item_operation.get:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.storage_location_category", "GET" ]
+
+ resource.storage_location_category.item_operation.put:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.storage_location_category", "PUT" ]
+
+ resource.storage_location_category.item_operation.delete:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.storage_location_category", "DELETE" ]
+
+ resource.storage_location_category:
+ parent: "api.resource"
+ arguments: [ "PartKeepr\StorageLocationBundle\Entity\StorageLocationCategory" ]
+ tags: [ { name: "api.resource" } ]
+ calls:
+ - method: "initItemOperations"
+ arguments: [ [ "@resource.storage_location_category.item_operation.get", "@resource.storage_location_category.item_operation.put", "@resource.storage_location_category.item_operation.delete", "@resource.storage_location_category.item_operation.move" ] ]
+ - method: "initNormalizationContext"
+ arguments: [ { groups: [ "default" ] } ]
+ - method: "initDenormalizationContext"
+ arguments:
+ - { groups: [ "default" ] }
+# ######################## Temporary Images ######################################
resource.tempimage.collection_operation.custom_post:
class: "Dunglas\ApiBundle\Api\Operation\Operation"
public: false
diff --git a/src/PartKeepr/CategoryBundle/Controller/CategoryController.php b/src/PartKeepr/CategoryBundle/Controller/CategoryController.php
@@ -0,0 +1,48 @@
+<?php
+namespace PartKeepr\CategoryBundle\Controller;
+
+use Dunglas\ApiBundle\Controller\ResourceController;
+use FOS\RestBundle\Controller\Annotations\RequestParam;
+use PartKeepr\CategoryBundle\Exception\MissingParentCategoryException;
+use PartKeepr\CategoryBundle\Exception\RootMayNotBeMovedException;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class CategoryController extends ResourceController
+{
+ /**
+ * Moves a node to another node
+ *
+ * @RequestParam(name="parent",description="The ID of the new parent")
+ * @param Request $request The request object
+ * @param int $id The ID of the node to move
+ *
+ * @return Response
+ *
+ * @throws MissingParentCategoryException If the parent category is not specified or invalid
+ * @throws RootMayNotBeMovedException If it is attempted to move the root category
+ */
+ public function moveAction(Request $request, $id)
+ {
+ $resource = $this->getResource($request);
+ $entity = $this->findOrThrowNotFound($resource, $id);
+ $parentId = $request->request->get("parent");
+
+ $parentEntity = $this->get("api.iri_converter")->getItemFromIri($parentId);
+
+
+ if ($parentEntity === null) {
+ throw new MissingParentCategoryException($parentId);
+ }
+
+ if ($entity->getLevel() === 0) {
+ throw new RootMayNotBeMovedException();
+ }
+
+ $entity->setParent($parentEntity);
+
+ $this->get("doctrine")->getManager()->flush();
+
+ return new Response($request->request->get("parent"));
+ }
+}
diff --git a/src/PartKeepr/FootprintBundle/Controller/FootprintCategoryController.php b/src/PartKeepr/FootprintBundle/Controller/FootprintCategoryController.php
@@ -1,48 +0,0 @@
-<?php
-namespace PartKeepr\FootprintBundle\Controller;
-
-use Dunglas\ApiBundle\Controller\ResourceController;
-use FOS\RestBundle\Controller\Annotations\RequestParam;
-use PartKeepr\CategoryBundle\Exception\MissingParentCategoryException;
-use PartKeepr\CategoryBundle\Exception\RootMayNotBeMovedException;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-
-class FootprintCategoryController extends ResourceController
-{
- /**
- * Moves a node to another node
- *
- * @RequestParam(name="parent",description="The ID of the new parent")
- * @param Request $request The request object
- * @param int $id The ID of the node to move
- *
- * @return Response
- *
- * @throws MissingParentCategoryException If the parent category is not specified or invalid
- * @throws RootMayNotBeMovedException If it is attempted to move the root category
- */
- public function moveAction(Request $request, $id)
- {
- $resource = $this->getResource($request);
- $entity = $this->findOrThrowNotFound($resource, $id);
- $parentId = $request->request->get("parent");
-
- $parentEntity = $this->get("api.iri_converter")->getItemFromIri($parentId);
-
-
- if ($parentEntity === null) {
- throw new MissingParentCategoryException($parentId);
- }
-
- if ($entity->getLevel() === 0) {
- throw new RootMayNotBeMovedException();
- }
-
- $entity->setParent($parentEntity);
-
- $this->get("doctrine")->getManager()->flush();
-
- return new Response($request->request->get("parent"));
- }
-}
diff --git a/src/PartKeepr/StorageLocationBundle/Entity/StorageLocationCategory.php b/src/PartKeepr/StorageLocationBundle/Entity/StorageLocationCategory.php
@@ -34,7 +34,7 @@ class StorageLocationCategory extends AbstractCategory
/**
* @ORM\OneToMany(targetEntity="PartKeepr\StorageLocationBundle\Entity\StorageLocation", mappedBy="category")
- *
+ * @Groups({"default"})
*/
protected $storageLocations;