mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
wip: refactor watchlist triggers
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Repository\WatchListRepository;
|
||||
@@ -90,6 +92,7 @@ use Symfony\Component\Uid\Uuid;
|
||||
security: 'object.user == user',
|
||||
name: 'update',
|
||||
processor: WatchListUpdateProcessor::class,
|
||||
extraProperties: ['standard_put' => false],
|
||||
),
|
||||
new Delete(
|
||||
security: 'object.user == user'
|
||||
@@ -101,10 +104,12 @@ class WatchList
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
public ?User $user = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: 'uuid')]
|
||||
#[Groups(['watchlist:item', 'watchlist:list', 'watchlist:token'])]
|
||||
private string $token;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Domain>
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Link;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Config\TriggerAction;
|
||||
use App\Repository\EventTriggerRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -12,28 +16,45 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
#[ORM\Entity(repositoryClass: EventTriggerRepository::class)]
|
||||
#[ApiResource(
|
||||
uriTemplate: '/watchlists/{watchListId}/triggers/{action}/{event}',
|
||||
operations: [
|
||||
new Get(),
|
||||
new GetCollection(
|
||||
uriTemplate: '/watchlists/{watchListId}/triggers',
|
||||
uriVariables: [
|
||||
'watchListId' => new Link(fromProperty: 'token', toProperty: 'watchList', fromClass: WatchList::class),
|
||||
],
|
||||
),
|
||||
new Put(
|
||||
uriTemplate: '/watchlists/{watchListId}/triggers',
|
||||
uriVariables: [
|
||||
'watchListId' => new Link(fromProperty: 'token', toProperty: 'watchList', fromClass: WatchList::class),
|
||||
],
|
||||
),
|
||||
new Delete(),
|
||||
],
|
||||
uriVariables: [
|
||||
'watchListId' => new Link(fromProperty: 'token', toProperty: 'watchList', fromClass: WatchList::class),
|
||||
'action' => 'action',
|
||||
'event' => 'event',
|
||||
],
|
||||
security: 'object.getWatchList().user == user',
|
||||
)]
|
||||
class WatchListTrigger
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[ORM\Column(length: 255, nullable: false)]
|
||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||
private ?string $event = null;
|
||||
private ?string $event;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(targetEntity: WatchList::class, cascade: ['persist'], inversedBy: 'watchListTriggers')]
|
||||
#[ORM\ManyToOne(targetEntity: WatchList::class, inversedBy: 'watchListTriggers')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'token', nullable: false, onDelete: 'CASCADE')]
|
||||
private ?WatchList $watchList = null;
|
||||
private ?WatchList $watchList;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(enumType: TriggerAction::class)]
|
||||
#[ORM\Column(nullable: false, enumType: TriggerAction::class)]
|
||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||
private ?TriggerAction $action = null;
|
||||
private ?TriggerAction $action;
|
||||
|
||||
public function getEvent(): ?string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user