Bläddra i källkod

various fixes

Olivier Massot 6 månader sedan
förälder
incheckning
a4ce27b745

+ 7 - 2
src/Entity/Shop/ShopRequest.php

@@ -10,7 +10,7 @@ use ApiPlatform\Metadata\Post;
 use App\Enum\Shop\ShopRequestStatus;
 use App\Enum\Shop\ShopRequestType;
 use App\State\Processor\Shop\NewStructureArtistPremiumTrialRequestProcessor;
-use App\State\Provider\Shop\NewStructureTrialRequestProvider;
+use App\State\Provider\Shop\ShopRequestProvider;
 use Doctrine\ORM\Mapping as ORM;
 use Doctrine\DBAL\Types\Types;
 use DateTimeImmutable;
@@ -19,7 +19,12 @@ use Symfony\Component\Validator\Constraints as Assert;
 /**
  * Une demande effectuée par un client via la boutique en ligne (ex: demande d'essai premium)
  */
-#[ApiResource(operations: [])]
+#[ApiResource(operations: [
+    new Get(
+        uriTemplate: '/shop/validate/{token}',
+        provider: ShopRequestProvider::class,
+    )
+])]
 #[ORM\Entity]
 class ShopRequest
 {

+ 0 - 89
src/MessageHandler/StartArtistPremiumTrialHandler.php

@@ -1,89 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\MessageHandler;
-
-use App\Message\StartArtistPremiumTrial;
-use App\Service\ApiLegacy\ApiLegacyRequestService;
-use Symfony\Component\Messenger\Attribute\AsMessageHandler;
-use Symfony\Component\HttpFoundation\Response;
-use Psr\Log\LoggerInterface;
-
-#[AsMessageHandler]
-class StartArtistPremiumTrialHandler
-{
-    public function __construct(
-        private readonly ApiLegacyRequestService $apiLegacyRequestService,
-        private readonly LoggerInterface $logger,
-        private readonly string $legacyBaseUrl
-    ) {
-    }
-
-    public function __invoke(StartArtistPremiumTrial $message): void
-    {
-        $organization = $message->getOrganization();
-        $representative = $message->getRepresentative();
-        $person = $representative->getPerson();
-
-        // Get the organization's address
-        $organizationAddressPostal = null;
-        foreach ($organization->getOrganizationAddressPostals() as $addressPostal) {
-            $organizationAddressPostal = $addressPostal;
-            break; // Get the first one
-        }
-
-        if (!$organizationAddressPostal) {
-            $this->logger->error('Cannot start artist premium trial: organization has no address');
-            return;
-        }
-
-        $addressPostal = $organizationAddressPostal->getAddressPostal();
-
-        // Get the representative's contact point
-        $contactPoint = null;
-        foreach ($person->getContactPoints() as $cp) {
-            $contactPoint = $cp;
-            break; // Get the first one
-        }
-
-        if (!$contactPoint) {
-            $this->logger->error('Cannot start artist premium trial: representative has no contact point');
-            return;
-        }
-
-        // Prepare the request data
-        $data = [
-            "organization" => [
-                "streetAddress" => $addressPostal->getStreetAddress(),
-                "streetAddressSecond" => $addressPostal->getStreetAddressSecond(),
-                "streetAddressThird" => $addressPostal->getStreetAddressThird(),
-                "cp" => $addressPostal->getPostalCode(),
-                "city" => $addressPostal->getAddressCity(),
-                "organizationAddressPostalId" => "/api/organization_address_postals/" . $organizationAddressPostal->getId(),
-                "name" => $organization->getName()
-            ],
-            "access" => [
-                "isAdmin" => $representative->isAdminAccess(),
-                "email" => $contactPoint->getEmail(),
-                "contactPointId" => "/api/contactpoints/" . $contactPoint->getId(),
-                "name" => $person->getName(),
-                "givenName" => $person->getGivenName(),
-                "function" => "representative",
-                "telphone" => (string)$contactPoint->getTelphone()
-            ]
-        ];
-
-        try {
-            $response = $this->apiLegacyRequestService->get('/api/trial/artist_premium', $data);
-
-            if ($response->getStatusCode() !== Response::HTTP_OK) {
-                $this->logger->error('Failed to start artist premium trial: ' . $response->getContent());
-            } else {
-                $this->logger->info('Successfully started artist premium trial for organization ' . $organization->getId());
-            }
-        } catch (\Exception $e) {
-            $this->logger->error('Exception while starting artist premium trial: ' . $e->getMessage());
-        }
-    }
-}

+ 3 - 3
src/Service/Shop/ShopService.php

@@ -50,7 +50,7 @@ readonly class ShopService
      */
     public function registerNewShopRequest(ShopRequestType $type, array $data): ShopRequest
     {
-        $this->validateShopRequest($type, $data);
+        $this->controlShopRequestData($type, $data);
         $request = $this->createRequest($type, $data);
         $this->sendRequestValidationLink($request);
 
@@ -65,7 +65,7 @@ readonly class ShopService
      * @param ShopRequestType $type
      * @param array<string, mixed> $data
      */
-    protected function validateShopRequest(ShopRequestType $type, array $data): void
+    protected function controlShopRequestData(ShopRequestType $type, array $data): void
     {
         if ($type === ShopRequestType::NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL) {
             // Create a minimal OrganizationCreationRequest with required info
@@ -133,7 +133,7 @@ readonly class ShopService
     {
         $validationUrl = UrlBuilder::concat(
             $this->baseUrl,
-            ['new-structure-trial-request', $shopRequest->getToken()]
+            ['shop/validate', $shopRequest->getToken()]
         );
 
         $data = $shopRequest->getData();

+ 1 - 1
src/State/Provider/Shop/NewStructureTrialRequestProvider.php → src/State/Provider/Shop/ShopRequestProvider.php

@@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 /**
  * Provider for NewStructureTrialRequest validation.
  */
-final class NewStructureTrialRequestProvider implements ProviderInterface
+final class ShopRequestProvider implements ProviderInterface
 {
     public function __construct(
         private readonly EntityManagerInterface $entityManager,