From 6d1c08ebf1d2215ff469100c12c19fda9ef56a9b Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Wed, 30 Dec 2020 13:53:24 -0800 Subject: [PATCH 1/2] adds serializer pack. --- composer.json | 5 +++++ composer.lock | 7 ++++--- symfony.lock | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 0aa8bb8a..04fc2e4e 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "ext-json": "*", "ext-mbstring": "*", "ext-pdo": "*", + "doctrine/annotations": "^1.0", "doctrine/doctrine-bundle": "^2.2", "doctrine/doctrine-fixtures-bundle": "^3.3", "doctrine/doctrine-migrations-bundle": "^2.0", @@ -25,6 +26,7 @@ "jms/i18n-routing-bundle": "@stable", "nelmio/api-doc-bundle": "^3.6", "nelmio/cors-bundle": "^2.1", + "phpdocumentor/reflection-docblock": "^5.2", "ramsey/uuid-doctrine": "^1.5", "sensio/framework-extra-bundle": "^5.0.0", "sensiolabs/security-checker": "^6.0", @@ -37,6 +39,9 @@ "symfony/monolog-bundle": "3.6.*", "symfony/polyfill-apcu": "^1.0", "symfony/polyfill-mbstring": "^1.14.0", + "symfony/property-access": "4.4.*", + "symfony/property-info": "4.4.*", + "symfony/serializer": "4.4.*", "symfony/swiftmailer-bundle": "^3.3.1", "symfony/templating": "^4", "symfony/yaml": "^5.1", diff --git a/composer.lock b/composer.lock index 5b198805..17154a12 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "79cff957d8723841ee23ef86ebd6edc6", + "content-hash": "25d9ef5e0bd85ade6a85db8d987f2f80", "packages": [ { "name": "behat/transliterator", @@ -9866,7 +9866,8 @@ "minimum-stability": "stable", "stability-flags": { "jms/i18n-routing-bundle": 0, - "squizlabs/php_codesniffer": 0 + "squizlabs/php_codesniffer": 0, + "symfony/browser-kit": 0 }, "prefer-stable": false, "prefer-lowest": false, @@ -9881,5 +9882,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } diff --git a/symfony.lock b/symfony.lock index 67e206ec..2d18c940 100644 --- a/symfony.lock +++ b/symfony.lock @@ -268,6 +268,9 @@ "config/packages/security.yaml" ] }, + "symfony/serializer-pack": { + "version": "v1.0.4" + }, "symfony/string": { "version": "v5.1.8" }, From 07d71a2cdc09c80fccfd2c9e0f8a20d396739020 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Wed, 30 Dec 2020 14:17:33 -0800 Subject: [PATCH 2/2] adds (experimental) api endpoint for restricted lists. --- src/Controller/ApiController.php | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index 3bdb0a17..77a557cf 100755 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -9,12 +9,15 @@ use App\Entity\DecklistInterface; use App\Entity\Pack; use App\Entity\PackInterface; +use App\Entity\Restriction; use App\Services\CardsData; use DateInterval; use DateTime; use Doctrine\Common\Collections\Criteria; use Exception; use Nelmio\ApiDocBundle\Annotation\Operation; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Swagger\Annotations as SWG; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -23,6 +26,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Serializer\SerializerInterface; /** * @package App\Controller @@ -601,4 +605,41 @@ public function listDecklistsByDateAction($date, Request $request, int $cacheExp $response->setContent($content); return $response; } + + /** + * @Route("/api/public/restrictions/", name="api_restrictions", methods={"GET"}, options={"i18n" = false}) + * + * Get the description of all the restricted lists as an array of JSON objects. + * + * @Operation( + * tags={"Public"}, + * summary="EXPERIMENTAL - DO NOT USE IN PRODUCTION. All the restricted lists.", + * @SWG\Response( + * response="200", + * description="Returned when successful" + * ) + * ) + * + * @param Request $request + * @param int $cacheExpiration + * @param SerializerInterface $serializer + * @return Response + */ + public function listRestrictions(Request $request, int $cacheExpiration, SerializerInterface $serializer): Response + { + $response = new Response(); + $response->setPublic(); + $response->setMaxAge($cacheExpiration); + $response->headers->add(array( + 'Access-Control-Allow-Origin' => '*', + 'Content-Language' => $request->getLocale() + )); + + $repo = $this->getDoctrine()->getRepository(Restriction::class); + $restrictions = $repo->findAll(); + $json = $serializer->serialize($restrictions, 'json'); + $response->headers->set('Content-Type', 'application/json'); + $response->setContent($json); + return $response; + } }