feat: add tracked domains table

This commit is contained in:
Maël Gangloff
2024-09-09 11:31:33 +02:00
parent 124168380a
commit 0e96404302
12 changed files with 201 additions and 39 deletions

View File

@@ -328,4 +328,56 @@ class WatchListController extends AbstractController
'Content-Type' => 'text/calendar; charset=utf-8',
]);
}
/**
* @throws \Exception
*/
#[Route(
path: '/api/tracked',
name: 'watchlist_get_tracked_domains',
defaults: [
'_api_resource_class' => WatchList::class,
'_api_operation_name' => 'get_tracked_domains',
]
)]
public function getTrackedDomains(): array
{
/** @var User $user */
$user = $this->getUser();
$domains = [];
/** @var WatchList $watchList */
foreach ($user->getWatchLists()->getIterator() as $watchList) {
/** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) {
/** @var DomainEvent|null $exp */
$exp = $domain->getEvents()->findFirst(fn (int $key, DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction());
if (!$domain->getDeleted()
&& null !== $exp && $exp->getDate() > new \DateTimeImmutable()
&& count(array_filter($domain->getEvents()->toArray(), fn (DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction())) > 0
&& !in_array($domain, $domains)) {
$domains[] = $domain;
}
}
}
usort($domains, function (Domain $d1, Domain $d2) {
$IMPORTANT_STATUS = ['pending delete', 'redemption period', 'auto renew period'];
/** @var \DateTimeImmutable $exp1 */
$exp1 = $d1->getEvents()->findFirst(fn (int $key, DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction())->getDate();
/** @var \DateTimeImmutable $exp2 */
$exp2 = $d2->getEvents()->findFirst(fn (int $key, DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction())->getDate();
$impStatus1 = count(array_intersect($IMPORTANT_STATUS, $d1->getStatus())) > 0;
$impStatus2 = count(array_intersect($IMPORTANT_STATUS, $d2->getStatus())) > 0;
return $impStatus1 && !$impStatus2 ? -1 : (
!$impStatus1 && $impStatus2 ? 2 :
$exp1 <=> $exp2
);
});
return $domains;
}
}

View File

@@ -57,7 +57,7 @@ class Domain
* @var Collection<int, DomainEvent>
*/
#[ORM\OneToMany(targetEntity: DomainEvent::class, mappedBy: 'domain', cascade: ['persist'], orphanRemoval: true)]
#[Groups(['domain:item'])]
#[Groups(['domain:item', 'domain:list'])]
private Collection $events;
/**
@@ -69,7 +69,7 @@ class Domain
private Collection $domainEntities;
#[ORM\Column(type: Types::SIMPLE_ARRAY, nullable: true)]
#[Groups(['domain:item'])]
#[Groups(['domain:item', 'domain:list'])]
private array $status = [];
/**
@@ -93,15 +93,16 @@ class Domain
private ?\DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['domain:item', 'domain:list'])]
private ?\DateTimeImmutable $updatedAt;
#[ORM\ManyToOne]
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: false)]
#[Groups(['domain:item'])]
#[Groups(['domain:item', 'domain:list'])]
private ?Tld $tld = null;
#[ORM\Column(nullable: false)]
#[Groups(['domain:item'])]
#[Groups(['domain:item', 'domain:list'])]
private ?bool $deleted;
public function __construct()

View File

@@ -8,7 +8,6 @@ use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\WatchListController;
use App\Repository\WatchListRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -27,6 +26,16 @@ use Symfony\Component\Uid\Uuid;
normalizationContext: ['groups' => 'watchlist:list'],
name: 'get_all_mine',
),
new GetCollection(
uriTemplate: '/tracked',
routeName: 'watchlist_get_tracked_domains',
normalizationContext: ['groups' => [
'domain:list',
'tld:list',
'event:list',
]],
name: 'get_tracked_domains'
),
new Get(
normalizationContext: ['groups' => [
'watchlist:item',
@@ -42,7 +51,6 @@ use Symfony\Component\Uid\Uuid;
),
new Get(
routeName: 'watchlist_calendar',
controller: WatchListController::class,
openapiContext: [
'responses' => [
'200' => [

View File

@@ -63,16 +63,16 @@ final readonly class UpdateDomainsFromWatchlistHandler
/** @var Domain $domain */
foreach ($watchList->getDomains()
->filter(fn ($domain) => $domain->getUpdatedAt()
->diff(
new \DateTimeImmutable())->days >= 7
->diff(new \DateTimeImmutable())->days >= 7
|| (
($domain->getUpdatedAt()
->diff(
new \DateTimeImmutable())->h * 60 + $domain->getUpdatedAt()
->diff(
new \DateTimeImmutable())->i) >= 50
->diff(new \DateTimeImmutable())->h * 60 + $domain->getUpdatedAt()
->diff(new \DateTimeImmutable())->i) >= 50
&& $this->RDAPService::isToBeWatchClosely($domain)
)
|| (count(array_intersect($domain->getStatus(), ['auto renew period', 'client hold', 'server hold'])) > 0
&& $domain->getUpdatedAt()->diff(new \DateTimeImmutable())->days >= 1
)
) as $domain
) {
$updatedAt = $domain->getUpdatedAt();

View File

@@ -76,7 +76,6 @@ readonly class RDAPService
private const IMPORTANT_EVENTS = [EventAction::Deletion->value, EventAction::Expiration->value];
private const IMPORTANT_STATUS = [
'auto renew period',
'redemption period',
'pending delete',
'pending create',
@@ -84,8 +83,6 @@ readonly class RDAPService
'pending restore',
'pending transfer',
'pending update',
'client hold',
'server hold',
'add period',
];