diff --git a/migrations/Version20260309213906.php b/migrations/Version20260309213906.php new file mode 100644 index 0000000..9a04ad9 --- /dev/null +++ b/migrations/Version20260309213906.php @@ -0,0 +1,34 @@ +addSql('CREATE TABLE project (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, color VARCHAR(7) NOT NULL, client_id INT DEFAULT NULL, PRIMARY KEY (id))'); + $this->addSql('CREATE INDEX IDX_2FB3D0EE19EB6921 ON project (client_id)'); + $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE19EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE SET NULL NOT DEFERRABLE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EE19EB6921'); + $this->addSql('DROP TABLE project'); + } +} diff --git a/src/Entity/Project.php b/src/Entity/Project.php new file mode 100644 index 0000000..b5acd6d --- /dev/null +++ b/src/Entity/Project.php @@ -0,0 +1,107 @@ + ['project:read']], + denormalizationContext: ['groups' => ['project:write']], + order: ['name' => 'ASC'], +)] +#[ORM\Entity(repositoryClass: ProjectRepository::class)] +class Project +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + #[Groups(['project:read'])] + private ?int $id = null; + + #[ORM\Column(length: 255)] + #[Groups(['project:read', 'project:write'])] + private ?string $name = null; + + #[ORM\Column(type: 'text', nullable: true)] + #[Groups(['project:read', 'project:write'])] + private ?string $description = null; + + #[ORM\Column(length: 7)] + #[Groups(['project:read', 'project:write'])] + private ?string $color = '#222783'; + + #[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'projects')] + #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] + #[Groups(['project:read', 'project:write'])] + private ?Client $client = null; + + 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 getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): static + { + $this->description = $description; + + return $this; + } + + public function getColor(): ?string + { + return $this->color; + } + + public function setColor(string $color): static + { + $this->color = $color; + + return $this; + } + + public function getClient(): ?Client + { + return $this->client; + } + + public function setClient(?Client $client): static + { + $this->client = $client; + + return $this; + } +} diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php new file mode 100644 index 0000000..6455dae --- /dev/null +++ b/src/Repository/ProjectRepository.php @@ -0,0 +1,17 @@ +