-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EV-244: Added user and org. entities
- Loading branch information
Showing
8 changed files
with
518 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230629133659 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 organization (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('CREATE TABLE organization_user (organization_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_B49AE8D432C8A3DE (organization_id), INDEX IDX_B49AE8D4A76ED395 (user_id), PRIMARY KEY(organization_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, enabled VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE organization_user ADD CONSTRAINT FK_B49AE8D432C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE'); | ||
$this->addSql('ALTER TABLE organization_user ADD CONSTRAINT FK_B49AE8D4A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE organization_user DROP FOREIGN KEY FK_B49AE8D432C8A3DE'); | ||
$this->addSql('ALTER TABLE organization_user DROP FOREIGN KEY FK_B49AE8D4A76ED395'); | ||
$this->addSql('DROP TABLE organization'); | ||
$this->addSql('DROP TABLE organization_user'); | ||
$this->addSql('DROP TABLE user'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230629133955 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('ALTER TABLE event ADD organization_id INT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA732C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id)'); | ||
$this->addSql('CREATE INDEX IDX_3BAE0AA732C8A3DE ON event (organization_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE event DROP FOREIGN KEY FK_3BAE0AA732C8A3DE'); | ||
$this->addSql('DROP INDEX IDX_3BAE0AA732C8A3DE ON event'); | ||
$this->addSql('ALTER TABLE event DROP organization_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230629134238 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('ALTER TABLE user ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL, ADD deleted_at DATETIME DEFAULT NULL, ADD created_by VARCHAR(255) DEFAULT NULL, ADD updated_by VARCHAR(255) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE user DROP created_at, DROP updated_at, DROP deleted_at, DROP created_by, DROP updated_by'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use App\Repository\OrganizationRepository; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity; | ||
use Gedmo\Timestampable\Traits\TimestampableEntity; | ||
|
||
#[ORM\Entity(repositoryClass: OrganizationRepository::class)] | ||
#[ApiResource] | ||
class Organization | ||
{ | ||
use TimestampableEntity; | ||
use SoftDeleteableEntity; | ||
|
||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column(length: 255)] | ||
private ?string $name = null; | ||
|
||
#[ORM\Column(length: 255)] | ||
private ?string $mail = null; | ||
|
||
#[ORM\Column(length: 255)] | ||
private ?string $url = null; | ||
|
||
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'organizations')] | ||
private Collection $Users; | ||
|
||
#[ORM\OneToMany(mappedBy: 'organization', targetEntity: Event::class)] | ||
private Collection $events; | ||
|
||
public function __construct() | ||
{ | ||
$this->Users = new ArrayCollection(); | ||
$this->events = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): static | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getMail(): ?string | ||
{ | ||
return $this->mail; | ||
} | ||
|
||
public function setMail(string $mail): static | ||
{ | ||
$this->mail = $mail; | ||
|
||
return $this; | ||
} | ||
|
||
public function getUrl(): ?string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function setUrl(string $url): static | ||
{ | ||
$this->url = $url; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<int, User> | ||
*/ | ||
public function getUsers(): Collection | ||
{ | ||
return $this->Users; | ||
} | ||
|
||
public function addUser(User $user): static | ||
{ | ||
if (!$this->Users->contains($user)) { | ||
$this->Users->add($user); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeUser(User $user): static | ||
{ | ||
$this->Users->removeElement($user); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<int, Event> | ||
*/ | ||
public function getEvents(): Collection | ||
{ | ||
return $this->events; | ||
} | ||
|
||
public function addEvent(Event $event): static | ||
{ | ||
if (!$this->events->contains($event)) { | ||
$this->events->add($event); | ||
$event->setOrganization($this); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeEvent(Event $event): static | ||
{ | ||
if ($this->events->removeElement($event)) { | ||
// set the owning side to null (unless already changed) | ||
if ($event->getOrganization() === $this) { | ||
$event->setOrganization(null); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.