Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Allow "friendsofsymfony/rest-bundle:^3.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed Aug 3, 2020
1 parent e370042 commit a133c43
Show file tree
Hide file tree
Showing 18 changed files with 322 additions and 192 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -63,12 +63,12 @@
"twig/twig": "^2.12.1"
},
"conflict": {
"friendsofsymfony/rest-bundle": "<2.2 || >=3.0",
"friendsofsymfony/rest-bundle": "<2.2",
"jms/serializer": "<0.13",
"sonata-project/core-bundle": "<3.20"
},
"require-dev": {
"friendsofsymfony/rest-bundle": "^2.2",
"friendsofsymfony/rest-bundle": "^2.2 || ^3.0",
"jms/serializer-bundle": "^2.0 || ^3.0",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
Expand Down
102 changes: 51 additions & 51 deletions src/BasketBundle/Controller/Api/BasketController.php
Expand Up @@ -14,8 +14,7 @@
namespace Sonata\BasketBundle\Controller\Api;

use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View as FOSRestView;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
Expand All @@ -26,6 +25,7 @@
use Sonata\Component\Basket\BasketManagerInterface;
use Sonata\Component\Product\ProductInterface;
use Sonata\Component\Product\ProductManagerInterface;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -63,11 +63,11 @@ class BasketController
protected $formFactory;

/**
* @param BasketManagerInterface $basketManager A Sonata ecommerce basket manager
* @param BasketElementManagerInterface $basketElementManager A Sonata ecommerce basket element manager
* @param ProductManagerInterface $productManager A Sonata ecommerce product manager
* @param BasketBuilderInterface $basketBuilder A Sonata ecommerce basket builder
* @param FormFactoryInterface $formFactory A Symfony form factory
* @param BasketManagerInterface $basketManager Sonata ecommerce basket manager
* @param BasketElementManagerInterface $basketElementManager Sonata ecommerce basket element manager
* @param ProductManagerInterface $productManager Sonata ecommerce product manager
* @param BasketBuilderInterface $basketBuilder Sonata ecommerce basket builder
* @param FormFactoryInterface $formFactory Symfony form factory
*/
public function __construct(BasketManagerInterface $basketManager, BasketElementManagerInterface $basketElementManager, ProductManagerInterface $productManager, BasketBuilderInterface $basketBuilder, FormFactoryInterface $formFactory)
{
Expand All @@ -86,13 +86,13 @@ public function __construct(BasketManagerInterface $basketManager, BasketElement
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for baskets list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of baskets by page")
* @QueryParam(name="orderBy", map=true, requirements="ASC|DESC", nullable=true, strict=true, description="Sort specification for the resultset (key is field, value is direction")
* @Rest\QueryParam(name="page", requirements="\d+", default="1", description="Page for baskets list pagination (1-indexed)")
* @Rest\QueryParam(name="count", requirements="\d+", default="10", description="Number of baskets by page")
* @Rest\QueryParam(name="orderBy", map=true, requirements="ASC|DESC", nullable=true, strict=true, description="Sort specification for the resultset (key is field, value is direction")
*
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
* @Rest\View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @return \Sonata\DatagridBundle\Pager\PagerInterface
* @return PagerInterface
*/
public function getBasketsAction(ParamFetcherInterface $paramFetcher)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public function getBasketsAction(ParamFetcherInterface $paramFetcher)
*
* @ApiDoc(
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="basket id"}
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"}
* },
* output={"class"="Sonata\Component\Basket\BasketInterface", "groups"={"sonata_api_read"}},
* statusCodes={
Expand All @@ -134,7 +134,7 @@ public function getBasketsAction(ParamFetcherInterface $paramFetcher)
* }
* )
*
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
* @Rest\View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @param $id
*
Expand All @@ -150,7 +150,7 @@ public function getBasketAction($id)
*
* @ApiDoc(
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="basket id"}
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"}
* },
* output={"class"="Sonata\Component\Basket\BasketInterface", "groups"={"sonata_api_read"}},
* statusCodes={
Expand All @@ -159,7 +159,7 @@ public function getBasketAction($id)
* }
* )
*
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
* @Rest\View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @param $id
*
Expand All @@ -183,7 +183,7 @@ public function getBasketBasketelementsAction($id)
* }
* )
*
* @param Request $request A Symfony request
* @param Request $request Symfony request
*
* @return FOSRestView|FormInterface
*/
Expand All @@ -197,7 +197,7 @@ public function postBasketAction(Request $request)
*
* @ApiDoc(
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="basket identifier"}
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"}
* },
* input={"class"="sonata_basket_api_form_basket", "name"="", "groups"={"sonata_api_write"}},
* output={"class"="Sonata\Component\Basket\BasketInterface", "groups"={"sonata_api_read"}},
Expand All @@ -208,8 +208,8 @@ public function postBasketAction(Request $request)
* }
* )
*
* @param int $id A Basket identifier
* @param Request $request A Symfony request
* @param int $id Basket identifier
* @param Request $request Symfony request
*
* @return FOSRestView|FormInterface
*/
Expand All @@ -223,7 +223,7 @@ public function putBasketAction($id, Request $request)
*
* @ApiDoc(
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="basket identifier"}
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"}
* },
* statusCodes={
* 200="Returned when basket is successfully deleted",
Expand All @@ -232,11 +232,11 @@ public function putBasketAction($id, Request $request)
* }
* )
*
* @param int $id A Basket identifier
* @param int $id Basket identifier
*
* @throws NotFoundHttpException
*
* @return \FOS\RestBundle\View\View
* @return FOSRestView
*/
public function deleteBasketAction($id)
{
Expand All @@ -256,7 +256,7 @@ public function deleteBasketAction($id)
*
* @ApiDoc(
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="basket identifier"},
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"},
* },
* input={"class"="sonata_basket_api_form_basket_element", "name"="", "groups"={"sonata_api_write"}},
* output={"class"="Sonata\Component\Basket\BasketInterface", "groups"={"sonata_api_read"}},
Expand All @@ -267,8 +267,8 @@ public function deleteBasketAction($id)
* }
* )
*
* @param int $id A basket identifier
* @param Request $request A Symfony request
* @param int $id Basket identifier
* @param Request $request Symfony request
*
* @return FOSRestView|FormInterface
*/
Expand All @@ -282,8 +282,8 @@ public function postBasketBasketelementsAction($id, Request $request)
*
* @ApiDoc(
* requirements={
* {"name"="basketId", "dataType"="integer", "requirement"="\d+", "description"="basket identifier"},
* {"name"="elementId", "dataType"="integer", "requirement"="\d+", "description"="element identifier"},
* {"name"="basketId", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"},
* {"name"="elementId", "dataType"="integer", "requirement"="\d+", "description"="Element identifier"},
* },
* input={"class"="sonata_basket_api_form_basket_element", "name"="", "groups"={"sonata_api_write"}},
* output={"class"="Sonata\Component\Basket\BasketInterface", "groups"={"sonata_api_read"}},
Expand All @@ -294,9 +294,9 @@ public function postBasketBasketelementsAction($id, Request $request)
* }
* )
*
* @param int $basketId A basket identifier
* @param int $elementId A basket element identifier
* @param Request $request A Symfony request
* @param int $basketId Basket identifier
* @param int $elementId Basket element identifier
* @param Request $request Symfony request
*
* @return FOSRestView|FormInterface
*/
Expand All @@ -310,8 +310,8 @@ public function putBasketBasketelementsAction($basketId, $elementId, Request $re
*
* @ApiDoc(
* requirements={
* {"name"="basketId", "dataType"="integer", "requirement"="\d+", "description"="basket identifier"},
* {"name"="elementId", "dataType"="integer", "requirement"="\d+", "description"="element identifier"},
* {"name"="basketId", "dataType"="integer", "requirement"="\d+", "description"="Basket identifier"},
* {"name"="elementId", "dataType"="integer", "requirement"="\d+", "description"="Element identifier"},
* },
* statusCodes={
* 200="Returned when basket is successfully deleted",
Expand All @@ -320,12 +320,12 @@ public function putBasketBasketelementsAction($basketId, $elementId, Request $re
* }
* )
*
* @param int $basketId A basket identifier
* @param int $elementId A basket element identifier
* @param int $basketId Basket identifier
* @param int $elementId Basket element identifier
*
* @throws NotFoundHttpException
*
* @return \FOS\RestBundle\View\View
* @return FOSRestView
*/
public function deleteBasketBasketelementsAction($basketId, $elementId)
{
Expand Down Expand Up @@ -368,9 +368,9 @@ public function deleteBasketBasketelementsAction($basketId, $elementId)
* Write a basket, this method is used by both POST and PUT action methods.
*
* @param Request $request Symfony request
* @param int|null $id A basket identifier
* @param int|null $id Basket identifier
*
* @return \FOS\RestBundle\View\View|FormInterface
* @return FOSRestView|FormInterface
*/
protected function handleWriteBasket($request, $id = null)
{
Expand Down Expand Up @@ -411,11 +411,11 @@ protected function handleWriteBasket($request, $id = null)
/**
* Write a basket element, this method is used by both POST and PUT action methods.
*
* @param int $basketId A Sonata ecommerce basket identifier
* @param Request $request A Symfony Request service
* @param int $elementId A Sonata ecommerce basket element identifier
* @param int $basketId Sonata ecommerce basket identifier
* @param Request $request Symfony Request service
* @param int $elementId Sonata ecommerce basket element identifier
*
* @return \FOS\RestBundle\View\View|FormInterface
* @return FOSRestView|FormInterface
*/
protected function handleWriteBasketElement($basketId, $request, $elementId = null)
{
Expand Down Expand Up @@ -469,11 +469,11 @@ protected function handleWriteBasketElement($basketId, $request, $elementId = nu
}

/**
* Retrieves basket with id $id or throws an exception if it doesn't exist.
* Retrieves basket with identifier $id or throws an exception if it doesn't exist.
*
* @param $id
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @throws NotFoundHttpException
*
* @return BasketInterface
*/
Expand All @@ -489,11 +489,11 @@ protected function getBasket($id)
}

/**
* Retrieves basket element with id $id or throws an exception if it doesn't exist.
* Retrieves basket element with identifier $id or throws an exception if it doesn't exist.
*
* @param $id
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @throws NotFoundHttpException
*
* @return BasketElementInterface
*/
Expand All @@ -509,11 +509,11 @@ protected function getBasketElement($id)
}

/**
* Retrieves product with id $id or throws an exception if it doesn't exist.
* Retrieves product with identifier $id or throws an exception if it doesn't exist.
*
* @param $id
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @throws NotFoundHttpException
*
* @return ProductInterface
*/
Expand All @@ -529,11 +529,11 @@ protected function getProduct($id)
}

/**
* Throws an exception if it already exists a basket with a specific customer id.
* Throws an exception if it already exists a basket with a specific customer identifier.
*
* @param $customerId
* @param mixed $customerId Customer identifier
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* @throws HttpException
*/
protected function checkExistingCustomerBasket($customerId): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/BasketBundle/Resources/config/routing/api.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://friendsofsymfony.github.com/schema/rest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://friendsofsymfony.github.com/schema/rest https://raw.github.com/FriendsOfSymfony/FOSRestBundle/master/Resources/config/schema/routing/rest_routing-1.0.xsd">
<import type="rest" resource="Sonata\BasketBundle\Controller\Api\BasketController" name-prefix="sonata_api_ecommerce_basket_"/>
<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 type="xml" resource="./api/basket.xml" name-prefix="sonata_api_ecommerce_basket_"/>
</routes>
27 changes: 27 additions & 0 deletions src/BasketBundle/Resources/config/routing/api/basket.xml
@@ -0,0 +1,27 @@
<?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">
<route id="get_baskets" path="/baskets.{_format}" methods="GET" controller="Sonata\BasketBundle\Controller\Api\BasketController::getBasketsAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="get_basket" path="/baskets/{id}.{_format}" methods="GET" controller="Sonata\BasketBundle\Controller\Api\BasketController::getBasketAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="get_basket_basketelements" path="/baskets/{id}/basketelements.{_format}" methods="GET" controller="Sonata\BasketBundle\Controller\Api\BasketController::postBasketAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="put_basket" path="/baskets/{id}.{_format}" methods="PUT" controller="Sonata\BasketBundle\Controller\Api\BasketController::putBasketAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="delete_basket" path="/baskets/{id}.{_format}" methods="DELETE" controller="Sonata\BasketBundle\Controller\Api\BasketController::deleteBasketAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="post_basket_basketelements" path="/baskets/{id}/basketelements.{_format}" methods="POST" controller="Sonata\BasketBundle\Controller\Api\BasketController::postBasketBasketelementsAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="put_basket_basketelements" path="/baskets/{basketId}/basketelements/{elementId}.{_format}" methods="PUT" controller="Sonata\BasketBundle\Controller\Api\BasketController::putBasketBasketelementsAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
<route id="delete_basket_basketelements" path="/baskets/{basketId}/basketelements/{elementId}.{_format}" methods="DELETE" controller="Sonata\BasketBundle\Controller\Api\BasketController::deleteBasketBasketelementsAction" format="json">
<requirement key="_format">json|xml|html</requirement>
</route>
</routes>

0 comments on commit a133c43

Please sign in to comment.