mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add WatchListTrigger Entity
This commit is contained in:
32
migrations/Version20240720210058.php
Normal file
32
migrations/Version20240720210058.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240720210058 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE watch_list_trigger (event VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, watch_list_id VARCHAR(36) NOT NULL, PRIMARY KEY(event, watch_list_id, "action"), CONSTRAINT FK_CF857A4CC4508918 FOREIGN KEY (watch_list_id) REFERENCES watch_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('CREATE INDEX IDX_CF857A4CC4508918 ON watch_list_trigger (watch_list_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE watch_list_trigger');
|
||||
}
|
||||
}
|
||||
9
src/Config/TriggerAction.php
Normal file
9
src/Config/TriggerAction.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
|
||||
enum TriggerAction: string
|
||||
{
|
||||
case SendEmail = 'email';
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class Domain
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['domain:item', 'domain:list', 'watchlist:item', 'watchlist:create'])]
|
||||
#[Groups(['domain:item', 'domain:list', 'watchlist:item'])]
|
||||
private ?string $ldhName = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
|
||||
@@ -13,6 +13,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: WatchListRepository::class)]
|
||||
@@ -59,10 +60,19 @@ class WatchList
|
||||
#[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
private Collection $domains;
|
||||
|
||||
/**
|
||||
* @var Collection<int, WatchListTrigger>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'watchList', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
#[SerializedName("triggers")]
|
||||
private Collection $watchListTriggers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->token = Uuid::v4();
|
||||
$this->domains = new ArrayCollection();
|
||||
$this->watchListTriggers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getToken(): ?string
|
||||
@@ -105,4 +115,34 @@ class WatchList
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, WatchListTrigger>
|
||||
*/
|
||||
public function getWatchListTriggers(): Collection
|
||||
{
|
||||
return $this->watchListTriggers;
|
||||
}
|
||||
|
||||
public function addWatchListTrigger(WatchListTrigger $watchListTrigger): static
|
||||
{
|
||||
if (!$this->watchListTriggers->contains($watchListTrigger)) {
|
||||
$this->watchListTriggers->add($watchListTrigger);
|
||||
$watchListTrigger->setWatchList($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeWatchListTrigger(WatchListTrigger $watchListTrigger): static
|
||||
{
|
||||
if ($this->watchListTriggers->removeElement($watchListTrigger)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($watchListTrigger->getWatchList() === $this) {
|
||||
$watchListTrigger->setWatchList(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
64
src/Entity/WatchListTrigger.php
Normal file
64
src/Entity/WatchListTrigger.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Config\EventAction;
|
||||
use App\Config\TriggerAction;
|
||||
use App\Repository\EventTriggerRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: EventTriggerRepository::class)]
|
||||
class WatchListTrigger
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(enumType: EventAction::class)]
|
||||
#[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
private ?EventAction $event = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(targetEntity: WatchList::class, inversedBy: 'watchListTriggers')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'token', nullable: false)]
|
||||
private ?WatchList $watchList = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(enumType: TriggerAction::class)]
|
||||
#[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
private ?TriggerAction $action = null;
|
||||
|
||||
public function getEvent(): ?EventAction
|
||||
{
|
||||
return $this->event;
|
||||
}
|
||||
|
||||
public function setEvent(EventAction $event): static
|
||||
{
|
||||
$this->event = $event;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWatchList(): ?WatchList
|
||||
{
|
||||
return $this->watchList;
|
||||
}
|
||||
|
||||
public function setWatchList(?WatchList $watchList): static
|
||||
{
|
||||
$this->watchList = $watchList;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction(): ?TriggerAction
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function setAction(TriggerAction $action): static
|
||||
{
|
||||
$this->action = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
43
src/Repository/EventTriggerRepository.php
Normal file
43
src/Repository/EventTriggerRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\WatchListTrigger;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<WatchListTrigger>
|
||||
*/
|
||||
class EventTriggerRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, WatchListTrigger::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return WatchListTrigger[] Returns an array of WatchListTrigger objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('e')
|
||||
// ->andWhere('e.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('e.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?WatchListTrigger
|
||||
// {
|
||||
// return $this->createQueryBuilder('e')
|
||||
// ->andWhere('e.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user