Ver código fonte

Adds event form retrieval from HelloAsso

This commit introduces the ability to retrieve event forms from HelloAsso.

It renames OrganizationForm to EventForm and updates the provider and
API resource configuration to fetch event-specific form data using an
event ID.

Additionally, it adds a try-catch block to the mercure hub publishing
to log any errors that may occur during the update process.
Olivier Massot 2 meses atrás
pai
commit
8fd1a18635

+ 7 - 28
src/ApiResources/HelloAsso/OrganizationForm.php → src/ApiResources/HelloAsso/EventForm.php

@@ -18,24 +18,14 @@ use App\State\Provider\HelloAsso\OrganizationFormProvider;
 #[ApiResource(
     operations: [
         new Get(
-            uriTemplate: '/helloasso/form/{id}',
-        ),
-        new GetCollection(
-            uriTemplate: '/helloasso/forms',
-        ),
+            uriTemplate: '/helloasso/form/{eventId}',
+        )
     ],
     provider: OrganizationFormProvider::class,
     security: 'is_granted("ROLE_ORGANIZATION")'
 )]
 class OrganizationForm
 {
-    /**
-     * Id 'bidon' ajouté par défaut pour permettre la construction
-     * de l'IRI par api platform.
-     */
-    #[ApiProperty(identifier: true)]
-    private int $id = 1;
-
     /**
      * Slug du formulaire
      */
@@ -50,18 +40,7 @@ class OrganizationForm
     /**
      * Url du formulaire
      */
-    private string $url;
-
-    public function getId(): int
-    {
-        return $this->id;
-    }
-
-    public function setId(int $id): self
-    {
-        $this->id = $id;
-        return $this;
-    }
+    private string $widgetUrl;
 
     public function getSlug(): string
     {
@@ -85,14 +64,14 @@ class OrganizationForm
         return $this;
     }
 
-    public function getUrl(): string
+    public function getWidgetUrl(): string
     {
-        return $this->url;
+        return $this->widgetUrl;
     }
 
-    public function setUrl(string $url): self
+    public function setWidgetUrl(string $widgetUrl): self
     {
-        $this->url = $url;
+        $this->widgetUrl = $widgetUrl;
         return $this;
     }
 }

+ 7 - 1
src/State/Processor/HelloAsso/ConnectionRequestProcessor.php

@@ -12,6 +12,7 @@ use App\Entity\Access\Access;
 use App\Service\HelloAsso\HelloAssoService;
 use App\Service\MercureHub;
 use http\Client\Response;
+use Psr\Log\LoggerInterface;
 use Symfony\Bundle\SecurityBundle\Security;
 
 /**
@@ -23,6 +24,7 @@ class ConnectionRequestProcessor implements ProcessorInterface
         private readonly HelloAssoService $helloAssoService,
         private Security                  $security,
         private MercureHub                $mercureHub,
+        private LoggerInterface           $logger,
     ) {
     }
 
@@ -58,7 +60,11 @@ class ConnectionRequestProcessor implements ProcessorInterface
 
         $helloAssoProfile = $this->helloAssoService->makeHelloAssoProfile($connectionRequest->getOrganizationId());
 
-        $this->mercureHub->publishUpdate($access->getId(), $helloAssoProfile);
+        try {
+            $this->mercureHub->publishUpdate($access->getId(), $helloAssoProfile);
+        } catch (\Exception $e) {
+            $this->logger->error('Error while sending mercure update : ' . $e->getMessage());
+        }
 
         return $connectionRequest;
     }

+ 3 - 3
src/State/Provider/HelloAsso/OrganizationFormProvider.php → src/State/Provider/HelloAsso/EventFormProvider.php

@@ -9,7 +9,7 @@ use ApiPlatform\Metadata\Operation;
 use ApiPlatform\State\ProviderInterface;
 use App\ApiResources\HelloAsso\AuthUrl;
 use App\ApiResources\HelloAsso\HelloAssoProfile;
-use App\ApiResources\HelloAsso\OrganizationForm;
+use App\ApiResources\HelloAsso\EventForm;
 use App\Entity\Access\Access;
 use App\Service\HelloAsso\HelloAssoService;
 use Doctrine\Common\Collections\ArrayCollection;
@@ -33,7 +33,7 @@ final class OrganizationFormProvider implements ProviderInterface
      *
      * @throws \Exception
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ArrayCollection | OrganizationForm
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ArrayCollection | EventForm
     {
         /** @var Access $access */
         $access = $this->security->getUser();
@@ -45,7 +45,7 @@ final class OrganizationFormProvider implements ProviderInterface
 
             return new ArrayCollection($forms);
         } else {
-            throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
+            $form = $this->helloAssoService->getHelloAssoEventForm($organizationId, $uriVariables['id']);
         }
     }
 }