feat: ovh API implement

This commit is contained in:
Maël Gangloff
2024-07-29 16:01:32 +02:00
parent 5063ee9a17
commit 0126238d45

View File

@@ -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();