From 0126238d45880f4ca60401d86afee793867c894a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Mon, 29 Jul 2024 16:01:32 +0200 Subject: [PATCH] feat: ovh API implement --- src/Controller/WatchListController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Controller/WatchListController.php b/src/Controller/WatchListController.php index f7ba7e3..39c9e29 100644 --- a/src/Controller/WatchListController.php +++ b/src/Controller/WatchListController.php @@ -2,10 +2,13 @@ namespace App\Controller; +use App\Config\TriggerAction; use App\Entity\User; use App\Entity\WatchList; +use App\Entity\WatchListTrigger; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\EntityManagerInterface; +use Exception; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; @@ -36,6 +39,9 @@ class WatchListController extends AbstractController return $user->getWatchLists(); } + /** + * @throws Exception + */ #[Route( path: '/api/watchlists', name: 'watchlist_create', @@ -49,6 +55,14 @@ class WatchListController extends AbstractController { $watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']); $watchList->setUser($this->getUser()); + /** @var WatchListTrigger $trigger */ + foreach ($watchList->getWatchListTriggers()->toArray() as $trigger) { + if ($trigger->getAction() === TriggerAction::SendEmail && $trigger->getConnector() !== null) + throw new Exception('No connector needed to send email'); + if ($trigger->getAction() === TriggerAction::BuyDomain && $trigger->getConnector() === null) + throw new Exception('Unable to order a domain name without a Connector'); + } + $this->em->persist($watchList); $this->em->flush();