Files
domain-watchdog/src/Entity/Connector.php

143 lines
3.6 KiB
PHP
Raw Normal View History

2024-07-28 21:14:41 +02:00
<?php
namespace App\Entity;
2024-07-29 15:28:05 +02:00
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
2024-07-28 21:14:41 +02:00
use App\Config\ConnectorProvider;
use App\Repository\ConnectorRepository;
2024-07-29 11:37:52 +02:00
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
2024-07-28 21:14:41 +02:00
use Doctrine\ORM\Mapping as ORM;
2024-07-29 15:28:05 +02:00
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Uid\Uuid;
#[ApiResource(
shortName: 'Connector',
operations: [
new GetCollection(
routeName: 'connector_get_all_mine',
normalizationContext: ['groups' => 'connector:list'],
name: 'get_all_mine',
),
new Get(
normalizationContext: ['groups' => 'connector:list']
),
new Post(
2024-07-29 19:04:50 +02:00
routeName: 'connector_create', normalizationContext: ['groups' => ['connector:create', 'connector:list']],
2024-07-29 15:28:05 +02:00
denormalizationContext: ['groups' => 'connector:create'],
name: 'create'
),
new Delete()
]
)]
2024-07-28 21:14:41 +02:00
#[ORM\Entity(repositoryClass: ConnectorRepository::class)]
class Connector
{
#[ORM\Id]
2024-07-29 15:28:05 +02:00
#[ORM\Column(type: 'uuid')]
2024-07-29 15:48:56 +02:00
#[Groups(['connector:list', 'watchlist:list'])]
2024-07-29 15:28:05 +02:00
private ?string $id;
2024-07-28 21:14:41 +02:00
#[ORM\ManyToOne(inversedBy: 'connectors')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
2024-07-29 15:28:05 +02:00
2024-07-29 15:48:56 +02:00
#[Groups(['connector:list', 'connector:create', 'watchlist:list'])]
2024-07-29 15:28:05 +02:00
#[ORM\Column(enumType: ConnectorProvider::class)]
private ?ConnectorProvider $provider = null;
#[Groups(['connector:create'])]
2024-07-28 21:14:41 +02:00
#[ORM\Column]
private array $authData = [];
2024-07-29 11:37:52 +02:00
/**
* @var Collection<int, WatchListTrigger>
*/
#[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'connector')]
private Collection $watchListTriggers;
2024-07-29 15:28:05 +02:00
2024-07-29 11:37:52 +02:00
public function __construct()
{
2024-07-29 15:28:05 +02:00
$this->id = Uuid::v4();
2024-07-29 11:37:52 +02:00
$this->watchListTriggers = new ArrayCollection();
}
2024-07-29 15:28:05 +02:00
public function getId(): ?string
2024-07-28 23:05:41 +02:00
{
return $this->id;
}
2024-07-28 21:14:41 +02:00
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getAuthData(): array
{
return $this->authData;
}
public function setAuthData(array $authData): static
{
$this->authData = $authData;
return $this;
}
2024-07-29 11:37:52 +02:00
/**
* @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->setConnector($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->getConnector() === $this) {
$watchListTrigger->setConnector(null);
}
}
return $this;
}
2024-07-29 15:28:05 +02:00
public function getProvider(): ?ConnectorProvider
{
return $this->provider;
}
public function setProvider(ConnectorProvider $provider): static
{
$this->provider = $provider;
return $this;
}
2024-07-28 21:14:41 +02:00
}