51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace com\fwdekker\deathnotifier\tracking;
|
|
|
|
use com\fwdekker\deathnotifier\Action;
|
|
use com\fwdekker\deathnotifier\validator\IsValidCsrfTokenRule;
|
|
use com\fwdekker\deathnotifier\validator\InvalidInputException;
|
|
use com\fwdekker\deathnotifier\validator\RuleSet;
|
|
use com\fwdekker\deathnotifier\validator\SessionRuleSet;
|
|
|
|
|
|
/**
|
|
* Lists all trackings of the current user.
|
|
*/
|
|
class ListTrackingsAction extends Action
|
|
{
|
|
/**
|
|
* @var TrackingList the list to return the current user's trackings from
|
|
*/
|
|
private readonly TrackingList $tracking_list;
|
|
|
|
|
|
/**
|
|
* Constructs a new `ListTrackingsAction`.
|
|
*
|
|
* @param TrackingList $tracking_list the list to return the current user's trackings from
|
|
*/
|
|
public function __construct(TrackingList $tracking_list)
|
|
{
|
|
$this->tracking_list = $tracking_list;
|
|
}
|
|
|
|
|
|
/**
|
|
* Lists all trackings of the current user.
|
|
*
|
|
* Requires that the user is logged in and that a valid CSRF token is present.
|
|
*
|
|
* @param array<int|string, mixed> $inputs `"token": string`: a valid CSRF token
|
|
* @return array<array{"name": string, "status": string, "is_deleted": bool}> all trackings of the current user
|
|
* @throws InvalidInputException if the user is not logged in or if no valid CSRF token is present
|
|
*/
|
|
public function handle(array $inputs): array
|
|
{
|
|
(new SessionRuleSet(validate_logged_in: true))->check($_SESSION);
|
|
(new RuleSet(["token" => [new IsValidCsrfTokenRule()]]))->check($inputs);
|
|
|
|
return $this->tracking_list->list_trackings($_SESSION["uuid"]);
|
|
}
|
|
}
|