From 86aa1d2f3f5d026ffa904ce64e8a915b05057cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sat, 20 Jul 2024 23:14:03 +0200 Subject: [PATCH] feat: add WatchListTrigger Entity --- migrations/Version20240720210058.php | 32 ++++++++++++ src/Config/TriggerAction.php | 9 ++++ src/Entity/Domain.php | 2 +- src/Entity/WatchList.php | 40 ++++++++++++++ src/Entity/WatchListTrigger.php | 64 +++++++++++++++++++++++ src/Repository/EventTriggerRepository.php | 43 +++++++++++++++ 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20240720210058.php create mode 100644 src/Config/TriggerAction.php create mode 100644 src/Entity/WatchListTrigger.php create mode 100644 src/Repository/EventTriggerRepository.php diff --git a/migrations/Version20240720210058.php b/migrations/Version20240720210058.php new file mode 100644 index 0000000..adaf21d --- /dev/null +++ b/migrations/Version20240720210058.php @@ -0,0 +1,32 @@ +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'); + } +} diff --git a/src/Config/TriggerAction.php b/src/Config/TriggerAction.php new file mode 100644 index 0000000..c2b29fe --- /dev/null +++ b/src/Config/TriggerAction.php @@ -0,0 +1,9 @@ + + */ + #[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 + */ + 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; + } } diff --git a/src/Entity/WatchListTrigger.php b/src/Entity/WatchListTrigger.php new file mode 100644 index 0000000..729d02e --- /dev/null +++ b/src/Entity/WatchListTrigger.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/src/Repository/EventTriggerRepository.php b/src/Repository/EventTriggerRepository.php new file mode 100644 index 0000000..f56f1b5 --- /dev/null +++ b/src/Repository/EventTriggerRepository.php @@ -0,0 +1,43 @@ + + */ +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() + // ; + // } +}