chore: rename Bookmark WatchList

This commit is contained in:
Maël Gangloff
2024-07-12 15:20:24 +02:00
parent 362f2b8b01
commit 2f977a8552
6 changed files with 54 additions and 60 deletions

View File

@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240712105119 extends AbstractMigration
final class Version20240712131220 extends AbstractMigration
{
public function getDescription(): string
{
@@ -20,11 +20,6 @@ final class Version20240712105119 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE bookmark_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_A650C0C4A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_A650C0C4A76ED395 ON bookmark_list (user_id)');
$this->addSql('CREATE TABLE bookmark_lists_domains (bookmark_token VARCHAR(36) NOT NULL, domain_handle VARCHAR(255) NOT NULL, PRIMARY KEY(bookmark_token, domain_handle), CONSTRAINT FK_C12B6400D0B0A7FC FOREIGN KEY (bookmark_token) REFERENCES bookmark_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C12B6400FEE32C10 FOREIGN KEY (domain_handle) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_C12B6400D0B0A7FC ON bookmark_lists_domains (bookmark_token)');
$this->addSql('CREATE INDEX IDX_C12B6400FEE32C10 ON bookmark_lists_domains (domain_handle)');
$this->addSql('CREATE TABLE domain (handle VARCHAR(255) NOT NULL, ldh_name VARCHAR(255) NOT NULL, whois_status VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:simple_array)
, PRIMARY KEY(handle))');
$this->addSql('CREATE TABLE domain_nameservers (domain_handle VARCHAR(255) NOT NULL, nameserver_handle VARCHAR(255) NOT NULL, PRIMARY KEY(domain_handle, nameserver_handle), CONSTRAINT FK_B6E6B63AFEE32C10 FOREIGN KEY (domain_handle) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B6E6B63A3DC1CB05 FOREIGN KEY (nameserver_handle) REFERENCES nameserver (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
@@ -51,6 +46,11 @@ final class Version20240712105119 extends AbstractMigration
$this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json)
, password VARCHAR(255) NOT NULL)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_EMAIL ON user (email)');
$this->addSql('CREATE TABLE watch_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_152B584BA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_152B584BA76ED395 ON watch_list (user_id)');
$this->addSql('CREATE TABLE bookmark_lists_domains (bookmark_token VARCHAR(36) NOT NULL, domain_handle VARCHAR(255) NOT NULL, PRIMARY KEY(bookmark_token, domain_handle), CONSTRAINT FK_C12B6400D0B0A7FC FOREIGN KEY (bookmark_token) REFERENCES watch_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C12B6400FEE32C10 FOREIGN KEY (domain_handle) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_C12B6400D0B0A7FC ON bookmark_lists_domains (bookmark_token)');
$this->addSql('CREATE INDEX IDX_C12B6400FEE32C10 ON bookmark_lists_domains (domain_handle)');
$this->addSql('CREATE TABLE messenger_messages (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, body CLOB NOT NULL, headers CLOB NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at DATETIME NOT NULL --(DC2Type:datetime_immutable)
, available_at DATETIME NOT NULL --(DC2Type:datetime_immutable)
, delivered_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
@@ -63,8 +63,6 @@ final class Version20240712105119 extends AbstractMigration
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE bookmark_list');
$this->addSql('DROP TABLE bookmark_lists_domains');
$this->addSql('DROP TABLE domain');
$this->addSql('DROP TABLE domain_nameservers');
$this->addSql('DROP TABLE domain_entity');
@@ -74,6 +72,8 @@ final class Version20240712105119 extends AbstractMigration
$this->addSql('DROP TABLE nameserver');
$this->addSql('DROP TABLE nameserver_entity');
$this->addSql('DROP TABLE user');
$this->addSql('DROP TABLE watch_list');
$this->addSql('DROP TABLE bookmark_lists_domains');
$this->addSql('DROP TABLE messenger_messages');
}
}

View File

@@ -52,10 +52,8 @@ class TestController extends AbstractController
} catch (ClientExceptionInterface $e) {
return new Response(null, Response::HTTP_INTERNAL_SERVER_ERROR);
}
/**
* Création du domaine
*/
$domain = $em->getRepository(Domain::class)->findOneBy(["handle" => $res['handle']]);
$domain = $domainRepository->findOneBy(["handle" => $res['handle']]);
if ($domain === null) $domain = new Domain();
$domain->setLdhName($res['ldhName'])
@@ -64,9 +62,6 @@ class TestController extends AbstractController
->setWhoisStatus($res['whoisStatus']);
/**
* Hydratation des événements
*/
foreach ($res['events'] as $rdapEvent) {
$event = $domainEventRepository->findOneBy([
"action" => EventAction::from($rdapEvent["eventAction"]),
@@ -81,9 +76,7 @@ class TestController extends AbstractController
}
/**
* Hydratation des entités
*/
foreach ($res['entities'] as $rdapEntity) {
$entity = $entityRepository->findOneBy([
"handle" => $rdapEntity['handle']
@@ -187,4 +180,5 @@ class TestController extends AbstractController
return new Response(null, Response::HTTP_OK);
}
}

View File

@@ -38,10 +38,10 @@ class Domain
private array $status = [];
/**
* @var Collection<int, BookmarkList>
* @var Collection<int, WatchList>
*/
#[ORM\ManyToMany(targetEntity: BookmarkList::class, mappedBy: 'domains', cascade: ['persist'])]
private Collection $bookmarkLists;
#[ORM\ManyToMany(targetEntity: WatchList::class, mappedBy: 'domains', cascade: ['persist'])]
private Collection $watchLists;
/**
* @var Collection<int, Nameserver>
@@ -57,7 +57,7 @@ class Domain
{
$this->events = new ArrayCollection();
$this->domainEntities = new ArrayCollection();
$this->bookmarkLists = new ArrayCollection();
$this->watchLists = new ArrayCollection();
$this->nameservers = new ArrayCollection();
}
@@ -173,27 +173,27 @@ class Domain
}
/**
* @return Collection<int, BookmarkList>
* @return Collection<int, WatchList>
*/
public function getBookmarkLists(): Collection
public function getWatchLists(): Collection
{
return $this->bookmarkLists;
return $this->watchLists;
}
public function addBookmarkList(BookmarkList $bookmarkList): static
public function addWatchList(WatchList $watchList): static
{
if (!$this->bookmarkLists->contains($bookmarkList)) {
$this->bookmarkLists->add($bookmarkList);
$bookmarkList->addDomain($this);
if (!$this->watchLists->contains($watchList)) {
$this->watchLists->add($watchList);
$watchList->addDomain($this);
}
return $this;
}
public function removeBookmarkList(BookmarkList $bookmarkList): static
public function removeWatchList(WatchList $watchList): static
{
if ($this->bookmarkLists->removeElement($bookmarkList)) {
$bookmarkList->removeDomain($this);
if ($this->watchLists->removeElement($watchList)) {
$watchList->removeDomain($this);
}
return $this;

View File

@@ -34,14 +34,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private ?string $password = null;
/**
* @var Collection<int, BookmarkList>
* @var Collection<int, WatchList>
*/
#[ORM\OneToMany(targetEntity: BookmarkList::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $bookmarkDomainLists;
#[ORM\OneToMany(targetEntity: WatchList::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $watchLists;
public function __construct()
{
$this->bookmarkDomainLists = new ArrayCollection();
$this->watchLists = new ArrayCollection();
}
public function getId(): ?int
@@ -121,29 +121,29 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
}
/**
* @return Collection<int, BookmarkList>
* @return Collection<int, WatchList>
*/
public function getBookmarkDomainLists(): Collection
public function getWatchLists(): Collection
{
return $this->bookmarkDomainLists;
return $this->watchLists;
}
public function addBookmarkDomainList(BookmarkList $bookmarkDomainList): static
public function addWatchList(WatchList $watchList): static
{
if (!$this->bookmarkDomainLists->contains($bookmarkDomainList)) {
$this->bookmarkDomainLists->add($bookmarkDomainList);
$bookmarkDomainList->setUser($this);
if (!$this->watchLists->contains($watchList)) {
$this->watchLists->add($watchList);
$watchList->setUser($this);
}
return $this;
}
public function removeBookmarkDomainList(BookmarkList $bookmarkDomainList): static
public function removeWatchList(WatchList $watchList): static
{
if ($this->bookmarkDomainLists->removeElement($bookmarkDomainList)) {
if ($this->watchLists->removeElement($watchList)) {
// set the owning side to null (unless already changed)
if ($bookmarkDomainList->getUser() === $this) {
$bookmarkDomainList->setUser(null);
if ($watchList->getUser() === $this) {
$watchList->setUser(null);
}
}

View File

@@ -2,29 +2,29 @@
namespace App\Entity;
use App\Repository\BookmarkListRepository;
use App\Repository\WatchListRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: BookmarkListRepository::class)]
class BookmarkList
#[ORM\Entity(repositoryClass: WatchListRepository::class)]
class WatchList
{
#[ORM\Id]
#[ORM\Column(length: 36)]
private string $token;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'bookmarkDomainLists')]
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
/**
* @var Collection<int, Domain>
*/
#[ORM\ManyToMany(targetEntity: Domain::class, inversedBy: 'bookmarkLists')]
#[ORM\JoinTable(name: 'bookmark_lists_domains',
joinColumns: [new ORM\JoinColumn(name: 'bookmark_token', referencedColumnName: 'token')],
#[ORM\ManyToMany(targetEntity: Domain::class, inversedBy: 'watchLists')]
#[ORM\JoinTable(name: 'watch_lists_domains',
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_handle', referencedColumnName: 'handle')])]
private Collection $domains;

View File

@@ -2,22 +2,22 @@
namespace App\Repository;
use App\Entity\BookmarkList;
use App\Entity\WatchList;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<BookmarkList>
* @extends ServiceEntityRepository<WatchList>
*/
class BookmarkListRepository extends ServiceEntityRepository
class WatchListRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BookmarkList::class);
parent::__construct($registry, WatchList::class);
}
// /**
// * @return BookmarkList[] Returns an array of BookmarkList objects
// * @return WatchList[] Returns an array of WatchList objects
// */
// public function findByExampleField($value): array
// {
@@ -31,7 +31,7 @@ class BookmarkListRepository extends ServiceEntityRepository
// ;
// }
// public function findOneBySomeField($value): ?BookmarkList
// public function findOneBySomeField($value): ?WatchList
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')