mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: add default createdAt updatedAt when domain is created
This commit is contained in:
@@ -2,18 +2,61 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\RDAPService;
|
||||
use App\Entity\DomainEntity;
|
||||
use App\Entity\DomainEvent;
|
||||
use App\Repository\DomainRepository;
|
||||
use Eluceo\iCal\Domain\Entity\Attendee;
|
||||
use Eluceo\iCal\Domain\Entity\Calendar;
|
||||
use Eluceo\iCal\Domain\Entity\Event;
|
||||
use Eluceo\iCal\Domain\ValueObject\Category;
|
||||
use Eluceo\iCal\Domain\ValueObject\Date;
|
||||
use Eluceo\iCal\Domain\ValueObject\EmailAddress;
|
||||
use Eluceo\iCal\Domain\ValueObject\SingleDay;
|
||||
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
|
||||
use Exception;
|
||||
use Sabre\VObject\Reader;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class DomainRefreshController extends AbstractController
|
||||
class DomainCalendarController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DomainRepository $domainRepository
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __invoke(string $ldhName, RDAPService $RDAPService): void
|
||||
public function __invoke(string $ldhName): Response
|
||||
{
|
||||
$RDAPService->registerDomains([$ldhName]);
|
||||
$calendar = new Calendar();
|
||||
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]);
|
||||
$attendees = [];
|
||||
|
||||
/** @var DomainEntity $entity */
|
||||
foreach ($domain->getDomainEntities()->toArray() as $entity) {
|
||||
$vCard = Reader::readJson($entity->getEntity()->getJCard());
|
||||
$email = (string)$vCard->EMAIL;
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) continue;
|
||||
|
||||
$attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string)$vCard->FN);
|
||||
}
|
||||
|
||||
/** @var DomainEvent $event */
|
||||
foreach ($domain->getEvents()->toArray() as $event) {
|
||||
$calendar->addEvent((new Event())
|
||||
->setSummary($domain->getLdhName() . ' (' . $event->getAction()->value . ')')
|
||||
->addCategory(new Category($event->getAction()->value))
|
||||
->setAttendees($attendees)
|
||||
->setOccurrence(new SingleDay(new Date($event->getDate())))
|
||||
);
|
||||
}
|
||||
return new Response((new CalendarFactory())->createCalendar($calendar), Response::HTTP_OK, [
|
||||
"Content-Type" => 'text/calendar; charset=utf-8'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,8 @@ class Domain
|
||||
$this->domainEntities = new ArrayCollection();
|
||||
$this->watchLists = new ArrayCollection();
|
||||
$this->nameservers = new ArrayCollection();
|
||||
$this->createdAt = new DateTimeImmutable('now');
|
||||
$this->updatedAt = new DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
public function getLdhName(): ?string
|
||||
|
||||
@@ -6,11 +6,13 @@ use App\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
||||
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
|
||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
#[ORM\Id]
|
||||
|
||||
@@ -2,17 +2,26 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\WatchListRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: WatchListRepository::class)]
|
||||
#[ApiResource(
|
||||
shortName: 'Watchlist',
|
||||
normalizationContext: ['groups' => 'watchlist:item', 'domain:list'],
|
||||
denormalizationContext: ['groups' => 'watchlist:item', 'domain:list'],
|
||||
paginationEnabled: false
|
||||
)]
|
||||
class WatchList
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 36)]
|
||||
#[Groups(['watchlist:item'])]
|
||||
private string $token;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
|
||||
@@ -26,6 +35,7 @@ class WatchList
|
||||
#[ORM\JoinTable(name: 'watch_lists_domains',
|
||||
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token')],
|
||||
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')])]
|
||||
#[Groups(['watchlist:item'])]
|
||||
private Collection $domains;
|
||||
|
||||
public function __construct()
|
||||
|
||||
Reference in New Issue
Block a user