Skip to content

Commit

Permalink
Ajout du modèle de donnée Token
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchois committed Jan 21, 2025
1 parent 63a3f83 commit c890eb1
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Domain/User/Token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Domain\User;

class Token
{
public function __construct(
private string $uuid,
private string $token,
private string $type,
private User $user,
private \DateTimeInterface $expirationDate,
) {
}

public function getUuid(): string
{
return $this->uuid;
}

public function getToken(): string
{
return $this->token;
}

public function getType(): string
{
return $this->type;
}

public function getUser(): User
{
return $this->user;
}

public function getExpirationDate(): \DateTimeInterface
{
return $this->expirationDate;
}
}
15 changes: 15 additions & 0 deletions src/Infrastructure/Persistence/Doctrine/Mapping/User.Token.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="App\Domain\User\Token" table="token">
<indexes>
<index columns="token"/>
</indexes>
<id name="uuid" type="guid" column="uuid"/>
<field name="token" type="string" length="100" nullable="false"/>
<field name="type" type="string" length="20" nullable="false"/>
<field name="expirationDate" type="datetimetz" nullable="false"/>
<many-to-one field="user" target-entity="App\Domain\User\User">
<join-column name="user_uuid" nullable="false" referenced-column-name="uuid" on-delete="CASCADE"/>
</many-to-one>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Infrastructure\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250121142614 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE token (uuid UUID NOT NULL, user_uuid UUID NOT NULL, token VARCHAR(100) NOT NULL, type VARCHAR(20) NOT NULL, expiration_date TIMESTAMP(0) WITH TIME ZONE NOT NULL, PRIMARY KEY(uuid))');
$this->addSql('CREATE INDEX IDX_5F37A13BABFE1C6F ON token (user_uuid)');
$this->addSql('CREATE INDEX IDX_5F37A13B5F37A13B ON token (token)');
$this->addSql('ALTER TABLE token ADD CONSTRAINT FK_5F37A13BABFE1C6F FOREIGN KEY (user_uuid) REFERENCES "user" (uuid) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE token DROP CONSTRAINT FK_5F37A13BABFE1C6F');
$this->addSql('DROP TABLE token');
}
}

0 comments on commit c890eb1

Please sign in to comment.