From 60c9e037a65fc040844b0a62a906e0edc4fbdfc4 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 25 Apr 2023 13:43:55 +0200 Subject: [PATCH] Addind API endpoint for savedExport --- .../Controller/SavedExportApiController.php | 18 ++++++++ .../ChillMainExtension.php | 36 +++++++++++++--- .../ChillMainBundle/Entity/SavedExport.php | 6 +++ .../ChillMainBundle/chill.api.specs.yaml | 42 ++++++++++++++++++- 4 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Controller/SavedExportApiController.php diff --git a/src/Bundle/ChillMainBundle/Controller/SavedExportApiController.php b/src/Bundle/ChillMainBundle/Controller/SavedExportApiController.php new file mode 100644 index 000000000..d6febc5c1 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/SavedExportApiController.php @@ -0,0 +1,18 @@ + [ 'installation' => [ - 'name' => $config['installation_name'], ], + 'name' => $config['installation_name'],], 'available_languages' => $config['available_languages'], 'add_address' => $config['add_address'], ], @@ -328,11 +330,12 @@ class ChillMainExtension extends Extension implements * Load parameter for configuration and set parameters for api. */ protected function configureCruds( - ContainerBuilder $container, - array $crudConfig, - array $apiConfig, + ContainerBuilder $container, + array $crudConfig, + array $apiConfig, Loader\YamlFileLoader $loader - ): void { + ): void + { if (count($crudConfig) === 0) { return; } @@ -746,8 +749,29 @@ class ChillMainExtension extends Extension implements ], ], ], + ], + [ + 'class' => SavedExport::class, + 'controller' => SavedExportApiController::class, + 'name' => 'saved_export', + 'base_path' => '/api/1.0/main/saved-export', + 'base_role' => 'ROLE_USER', + 'actions' => [ + '_index' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + ], + ], + '_entity' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + ], + ], + ], ] - ], + ] ]); } } diff --git a/src/Bundle/ChillMainBundle/Entity/SavedExport.php b/src/Bundle/ChillMainBundle/Entity/SavedExport.php index 81ca33e72..7f2cf5afb 100644 --- a/src/Bundle/ChillMainBundle/Entity/SavedExport.php +++ b/src/Bundle/ChillMainBundle/Entity/SavedExport.php @@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\Entity @@ -33,6 +34,7 @@ class SavedExport implements TrackCreationInterface, TrackUpdateInterface /** * @ORM\Column(type="text", nullable=false, options={"default": ""}) * @Assert\NotBlank + * @Groups({"read"}) */ private string $description = ''; @@ -45,22 +47,26 @@ class SavedExport implements TrackCreationInterface, TrackUpdateInterface * @ORM\Id * @ORM\Column(name="id", type="uuid", unique="true") * @ORM\GeneratedValue(strategy="NONE") + * @Groups({"read"}) */ private UuidInterface $id; /** * @ORM\Column(type="json", nullable=false, options={"default": "[]"}) + * @Groups({"read"}) */ private array $options = []; /** * @ORM\Column(type="text", nullable=false, options={"default": ""}) * @Assert\NotBlank + * @Groups({"read"}) */ private string $title = ''; /** * @ORM\ManyToOne(targetEntity=User::class) + * @Groups({"read"}) */ private User $user; diff --git a/src/Bundle/ChillMainBundle/chill.api.specs.yaml b/src/Bundle/ChillMainBundle/chill.api.specs.yaml index 98e0e915e..3531085bd 100644 --- a/src/Bundle/ChillMainBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillMainBundle/chill.api.specs.yaml @@ -10,6 +10,22 @@ servers: components: schemas: + SavedExport: + type: object + properties: + id: + type: integer + user_id: + type: integer + description: + type: string + exportalias: + type: string + options: + type: string #TODO -> je pense que c'est object + title: + type: string + User: type: object properties: @@ -791,7 +807,7 @@ paths: /1.0/main/civility.json: get: tags: - - civility + - civility summary: Return all civility types responses: 200: @@ -843,3 +859,27 @@ paths: 403: description: "Unauthorized" + /1.0/main/saved-export/{id}.json: + get: + tags: + - export + summary: Return a specific saved export who is saved by an existing user. + parameters: + - name: id + in: path + required: true + description: The saved export id + schema: + type: string + format: string + responses: + 200: + description: "ok" + content: + application/json: + schema: + type: string + items: + $ref: '#/components/schemas/SavedExport' + 403: + description: "Unauthorized"