mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: user can enable/disable a watchlist
This commit is contained in:
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -95,6 +96,12 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
security: 'object.getUser() == user',
|
||||
processor: WatchlistUpdateProcessor::class,
|
||||
),
|
||||
new Patch(
|
||||
normalizationContext: ['groups' => 'watchlist:list'],
|
||||
denormalizationContext: ['groups' => ['watchlist:update']],
|
||||
security: 'object.getUser() == user',
|
||||
processor: WatchlistUpdateProcessor::class,
|
||||
),
|
||||
new Delete(
|
||||
security: 'object.getUser() == user'
|
||||
),
|
||||
@@ -208,6 +215,10 @@ class Watchlist
|
||||
])]
|
||||
private array $trackedEppStatus = [];
|
||||
|
||||
#[ORM\Column(type: Types::BOOLEAN)]
|
||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
private ?bool $enabled = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->token = Uuid::v4();
|
||||
@@ -332,4 +343,16 @@ class Watchlist
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isEnabled(): ?bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
public function setEnabled(bool $enabled): static
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ final readonly class ProcessWatchlistTriggerHandler
|
||||
*/
|
||||
|
||||
$randomizer = new Randomizer();
|
||||
$watchlists = $randomizer->shuffleArray($this->watchlistRepository->findAll());
|
||||
$watchlists = $randomizer->shuffleArray($this->watchlistRepository->getEnabledWatchlist());
|
||||
|
||||
/** @var Watchlist $watchlist */
|
||||
foreach ($watchlists as $watchlist) {
|
||||
|
||||
@@ -25,6 +25,14 @@ class WatchlistRepository extends ServiceEntityRepository
|
||||
->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function getEnabledWatchlist()
|
||||
{
|
||||
return $this->createQueryBuilder('w')
|
||||
->select()
|
||||
->where('w.isEnabled = true')
|
||||
->getQuery()->execute();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Watchlist[] Returns an array of Watchlist objects
|
||||
// */
|
||||
|
||||
Reference in New Issue
Block a user