From 71a3a1924a306ffa6d33b797ba3ba0531ee7ccf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 17 Apr 2024 12:51:31 +0200 Subject: [PATCH] Add Motive API and related fixtures to ChillTicketBundle This update introduces the Motive API Controller to the ChillTicket bundle with its corresponding service configuration. Also included are related data fixtures for loading motive information. The motive entity has been updated to improve its serialization properties and new types were added to the TypeScript definitions of the bundle. --- .../ChillTicketBundle/chill.api.specs.yaml | 25 ++++++ .../src/Controller/MotiveApiController.php | 25 ++++++ .../src/DataFixtures/ORM/LoadMotives.php | 82 +++++++++++++++++++ .../ChillTicketExtension.php | 40 ++++++++- .../ChillTicketBundle/src/Entity/Motive.php | 5 ++ .../src/Resources/public/types.ts | 8 ++ .../src/config/services.yaml | 3 + 7 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillTicketBundle/chill.api.specs.yaml create mode 100644 src/Bundle/ChillTicketBundle/src/Controller/MotiveApiController.php create mode 100644 src/Bundle/ChillTicketBundle/src/DataFixtures/ORM/LoadMotives.php diff --git a/src/Bundle/ChillTicketBundle/chill.api.specs.yaml b/src/Bundle/ChillTicketBundle/chill.api.specs.yaml new file mode 100644 index 000000000..e15b57ba5 --- /dev/null +++ b/src/Bundle/ChillTicketBundle/chill.api.specs.yaml @@ -0,0 +1,25 @@ +components: + schemas: + Motive: + type: object + properties: + id: + type: integer + label: + type: object + additionalProperties: + type: string + example: + fr: Retard de livraison + active: + type: boolean + +paths: + /1.0/ticket/motive.json: + get: + tags: + - ticket + summary: A list of available ticket's motive + responses: + 200: + description: "OK" diff --git a/src/Bundle/ChillTicketBundle/src/Controller/MotiveApiController.php b/src/Bundle/ChillTicketBundle/src/Controller/MotiveApiController.php new file mode 100644 index 000000000..d3f682615 --- /dev/null +++ b/src/Bundle/ChillTicketBundle/src/Controller/MotiveApiController.php @@ -0,0 +1,25 @@ +andWhere('e.active = TRUE'); + } +} diff --git a/src/Bundle/ChillTicketBundle/src/DataFixtures/ORM/LoadMotives.php b/src/Bundle/ChillTicketBundle/src/DataFixtures/ORM/LoadMotives.php new file mode 100644 index 000000000..e29470a3f --- /dev/null +++ b/src/Bundle/ChillTicketBundle/src/DataFixtures/ORM/LoadMotives.php @@ -0,0 +1,82 @@ +setLabel(['fr' => trim($label)]); + + $manager->persist($motive); + } + + $manager->flush(); + } + + private const MOTIVES = <<<'TXT' + Coordonnées + Horaire de passage + Retard de livraison + Erreur de livraison + Colis incomplet + MATLOC + Retard DASRI + Planning d'astreintes + Planning des tournées + Contrôle pompe + Changement de rendez-vous + Renseignement facturation/prestation + Décès patient + Demande de prise en charge + Information absence + Demande bulletin de situation + Difficultés accès logement + Déplacement inutile + Problème de prélèvement/de commande + Parc auto + Demande d'admission + Retrait de matériel au domicile + Comptes-rendus + Démarchage commercial + Demande de transport + Demande laboratoire + Demande admission + Suivi de prise en charge + Mauvaise adresse + Patient absent + Annulation + Colis perdu + Changement de rendez-vous + Coordination interservices + Problème de substitution produits + Problème ordonnance + Réclamations facture + Préparation urgente + TXT; +} diff --git a/src/Bundle/ChillTicketBundle/src/DependencyInjection/ChillTicketExtension.php b/src/Bundle/ChillTicketBundle/src/DependencyInjection/ChillTicketExtension.php index 8ee95d06c..f2222aa7a 100644 --- a/src/Bundle/ChillTicketBundle/src/DependencyInjection/ChillTicketExtension.php +++ b/src/Bundle/ChillTicketBundle/src/DependencyInjection/ChillTicketExtension.php @@ -11,16 +11,54 @@ declare(strict_types=1); namespace Chill\TicketBundle\DependencyInjection; +use Chill\TicketBundle\Controller\MotiveApiController; +use Chill\TicketBundle\Entity\Motive; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\HttpFoundation\Request; -class ChillTicketExtension extends Extension +class ChillTicketExtension extends Extension implements PrependExtensionInterface { public function load(array $configs, ContainerBuilder $container) { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); } + + public function prepend(ContainerBuilder $container) + { + $this->prependApi($container); + } + + private function prependApi(ContainerBuilder $container): void + { + $container->prependExtensionConfig('chill_main', [ + 'apis' => [ + [ + 'class' => Motive::class, + 'name' => 'motive', + 'base_path' => '/api/1.0/ticket/motive', + 'controller' => MotiveApiController::class, + '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/ChillTicketBundle/src/Entity/Motive.php b/src/Bundle/ChillTicketBundle/src/Entity/Motive.php index fd744392c..eceefdf46 100644 --- a/src/Bundle/ChillTicketBundle/src/Entity/Motive.php +++ b/src/Bundle/ChillTicketBundle/src/Entity/Motive.php @@ -12,20 +12,25 @@ declare(strict_types=1); namespace Chill\TicketBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation as Serializer; #[ORM\Entity()] #[ORM\Table(name: 'motive', schema: 'chill_ticket')] +#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['ticket_motive' => Motive::class])] class Motive { #[ORM\Id] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER, nullable: false)] #[ORM\GeneratedValue(strategy: 'AUTO')] + #[Serializer\Groups(['read'])] private ?int $id = null; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])] + #[Serializer\Groups(['read'])] private array $label = []; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN, nullable: false, options: ['default' => true])] + #[Serializer\Groups(['read'])] private bool $active = true; public function isActive(): bool diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/types.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/types.ts index 7302f2485..e7eed8575 100644 --- a/src/Bundle/ChillTicketBundle/src/Resources/public/types.ts +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/types.ts @@ -1,3 +1,11 @@ +import {TranslatableString} from "../../../../ChillMainBundle/Resources/public/types"; + export interface Ticket { id: number } + +export interface Motive { + id: number, + active: boolean, + label: TranslatableString +} diff --git a/src/Bundle/ChillTicketBundle/src/config/services.yaml b/src/Bundle/ChillTicketBundle/src/config/services.yaml index db5a5cf27..0ccd26525 100644 --- a/src/Bundle/ChillTicketBundle/src/config/services.yaml +++ b/src/Bundle/ChillTicketBundle/src/config/services.yaml @@ -11,3 +11,6 @@ services: Chill\TicketBundle\Action\Ticket\Handler\: resource: '../Action/Ticket/Handler/' + + Chill\TicketBundle\DataFixtures\: + resource: '../DataFixtures/'