Skip to content

Commit

Permalink
Use XML for ReST API routing
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys authored and jordisala1991 committed Jul 27, 2020
1 parent 4065c74 commit 0785115
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 41 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"nelmio/api-doc-bundle": "^2.4",
"sensio/framework-extra-bundle": "^5.5",
"sonata-project/doctrine-orm-admin-bundle": "^3.18",
"sonata-project/google-authenticator": "^1.0 || ^2.0",
"symfony/browser-kit": "^4.4 || ^5.1",
Expand Down
17 changes: 0 additions & 17 deletions src/Controller/Api/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
namespace Sonata\UserBundle\Controller\Api;

use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\Annotations\Delete;
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Put;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Request\ParamFetcherInterface;
Expand All @@ -30,12 +26,9 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;

/**
* @author Hugo Briand <[email protected]>
*
* @Route(requirements={"_format": "json|xml|html"}, defaults={"_format": "json"})
*/
class GroupController
{
Expand Down Expand Up @@ -67,8 +60,6 @@ public function __construct(GroupManagerInterface $groupManager, FormFactoryInte
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}}
* )
*
* @Get("/groups.{_format}", name="get_groups")
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for groups list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of groups by page")
* @QueryParam(name="orderBy", map=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query groups order by clause (key is field, value is direction")
Expand Down Expand Up @@ -118,8 +109,6 @@ public function getGroupsAction(ParamFetcherInterface $paramFetcher)
* }
* )
*
* @Get("/group/{id}.{_format}", name="get_group")
*
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @param $id
Expand All @@ -143,8 +132,6 @@ public function getGroupAction($id)
* }
* )
*
* @Post("/group.{_format}", name="post_group")
*
* @param Request $request A Symfony request
*
* @throws NotFoundHttpException
Expand Down Expand Up @@ -172,8 +159,6 @@ public function postGroupAction(Request $request)
* }
* )
*
* @Put("/group/{id}.{_format}", name="put_group")
*
* @param int $id Group identifier
* @param Request $request A Symfony request
*
Expand All @@ -200,8 +185,6 @@ public function putGroupAction($id, Request $request)
* }
* )
*
* @Delete("/group/{id}.{_format}", name="delete_group")
*
* @param int $id A Group identifier
*
* @throws NotFoundHttpException
Expand Down
21 changes: 0 additions & 21 deletions src/Controller/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
namespace Sonata\UserBundle\Controller\Api;

use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\Annotations\Delete;
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Put;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Request\ParamFetcherInterface;
Expand All @@ -32,12 +28,9 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;

/**
* @author Hugo Briand <[email protected]>
*
* @Route(requirements={"_format": "json|xml|html"}, defaults={"_format": "json"})
*/
class UserController
{
Expand Down Expand Up @@ -71,8 +64,6 @@ public function __construct(UserManagerInterface $userManager, GroupManagerInter
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}}
* )
*
* @Get("/users.{_format}", name="get_users")
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for users list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of users by page")
* @QueryParam(name="orderBy", map=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query users order by clause (key is field, value is direction")
Expand Down Expand Up @@ -122,8 +113,6 @@ public function getUsersAction(ParamFetcherInterface $paramFetcher)
* }
* )
*
* @Get("/user/{id}.{_format}", name="get_user")
*
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @param $id
Expand All @@ -147,8 +136,6 @@ public function getUserAction($id)
* }
* )
*
* @Post("/user.{_format}", name="post_user")
*
* @param Request $request A Symfony request
*
* @throws NotFoundHttpException
Expand Down Expand Up @@ -176,8 +163,6 @@ public function postUserAction(Request $request)
* }
* )
*
* @Put("/user/{id}.{_format}", name="put_user")
*
* @param int $id User id
* @param Request $request A Symfony request
*
Expand All @@ -204,8 +189,6 @@ public function putUserAction($id, Request $request)
* }
* )
*
* @Delete("/user/{id}.{_format}", name="delete_user")
*
* @param int $id An User identifier
*
* @throws NotFoundHttpException
Expand Down Expand Up @@ -237,8 +220,6 @@ public function deleteUserAction($id)
* }
* )
*
* @Post("/user/{userId}/{groupId}.{_format}", name="post_user_group")
*
* @param int $userId A User identifier
* @param int $groupId A Group identifier
*
Expand Down Expand Up @@ -280,8 +261,6 @@ public function postUserGroupAction($userId, $groupId)
* }
* )
*
* @Delete("/user/{userId}/{groupId}.{_format}", name="delete_user_group")
*
* @param int $userId A User identifier
* @param int $groupId A Group identifier
*
Expand Down
38 changes: 36 additions & 2 deletions src/Resources/config/routing/api.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="Sonata\UserBundle\Controller\Api\UserController" type="annotation" name-prefix="sonata_api_user_user_"/>
<import resource="Sonata\UserBundle\Controller\Api\GroupController" type="annotation" name-prefix="sonata_api_user_group_"/>
<route id="sonata_api_user_group_delete_group" path="/group/{id}.{_format}" methods="DELETE" controller="Sonata\UserBundle\Controller\Api\GroupController::deleteGroupAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_group_get_group" path="/group/{id}.{_format}" methods="GET" controller="Sonata\UserBundle\Controller\Api\GroupController::getGroupAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_group_get_groups" path="/groups.{_format}" methods="GET" controller="Sonata\UserBundle\Controller\Api\GroupController::getGroupsAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_group_post_group" path="/group.{_format}" methods="POST" controller="Sonata\UserBundle\Controller\Api\GroupController::postGroupAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_group_put_group" path="/group/{id}.{_format}" methods="PUT" controller="Sonata\UserBundle\Controller\Api\GroupController::putGroupAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_delete_user" path="/user/{id}.{_format}" methods="DELETE" controller="Sonata\UserBundle\Controller\Api\UserController::deleteUserAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_delete_user_group" path="/user/{userId}/{groupId}.{_format}" methods="DELETE" controller="Sonata\UserBundle\Controller\Api\UserController::deleteUserGroupAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_get_user" path="/user/{id}.{_format}" methods="GET" controller="Sonata\UserBundle\Controller\Api\UserController::getUserAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_get_users" path="/users.{_format}" methods="GET" controller="Sonata\UserBundle\Controller\Api\UserController::getUsersAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_post_user" path="/user.{_format}" methods="POST" controller="Sonata\UserBundle\Controller\Api\UserController::postUsersAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_post_user_group" path="/user/{userId}/{groupId}.{_format}" methods="POST" controller="Sonata\UserBundle\Controller\Api\UserController::postUserGroupAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="sonata_api_user_user_put_user" path="/user/{id}.{_format}" methods="PUT" controller="Sonata\UserBundle\Controller\Api\UserController::putUsersAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
</routes>

0 comments on commit 0785115

Please sign in to comment.