-
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.
close: #13 * refac(logger): replace LoggerInterface with ExceptionLogger * refac(Service): rename Project classes * feat: add Category entity * chore: update monolog config * feat(category): add fixtures * refac(entities): add cascade/orphanRemoval attributes
- Loading branch information
Showing
20 changed files
with
401 additions
and
125 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20230912004347 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add Project and Category'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TABLE category (id UUID NOT NULL, name VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, archived_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, slug VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('COMMENT ON COLUMN category.id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN category.created_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN category.updated_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN category.archived_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('CREATE TABLE category_project (category_id UUID NOT NULL, project_id UUID NOT NULL, PRIMARY KEY(category_id, project_id))'); | ||
$this->addSql('CREATE INDEX IDX_E86B909012469DE2 ON category_project (category_id)'); | ||
$this->addSql('CREATE INDEX IDX_E86B9090166D1F9C ON category_project (project_id)'); | ||
$this->addSql('COMMENT ON COLUMN category_project.category_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN category_project.project_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('CREATE TABLE project (id UUID NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, archived_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, slug VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('COMMENT ON COLUMN project.id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN project.created_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN project.updated_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN project.archived_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('ALTER TABLE category_project ADD CONSTRAINT FK_E86B909012469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE category_project ADD CONSTRAINT FK_E86B9090166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE SCHEMA public'); | ||
$this->addSql('ALTER TABLE category_project DROP CONSTRAINT FK_E86B909012469DE2'); | ||
$this->addSql('ALTER TABLE category_project DROP CONSTRAINT FK_E86B9090166D1F9C'); | ||
$this->addSql('DROP TABLE category'); | ||
$this->addSql('DROP TABLE category_project'); | ||
$this->addSql('DROP TABLE project'); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Entity\Category; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
final class CategoryFixtures extends Fixture implements OrderedFixtureInterface | ||
{ | ||
public const CATEGORY_QUANTITY = 20; | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
for ($i = 1; $i <= self::CATEGORY_QUANTITY; ++$i) { | ||
$category = (new Category())->setName("category-$i"); | ||
$manager->persist($category); | ||
} | ||
|
||
$manager->flush(); | ||
} | ||
|
||
public function getOrder(): int | ||
{ | ||
return 1; | ||
} | ||
} |
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,115 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\CategoryRepository; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Bridge\Doctrine\Types\UuidType; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
#[ORM\Entity(repositoryClass: CategoryRepository::class)] | ||
#[ORM\Table(name: 'category')] | ||
#[ORM\HasLifecycleCallbacks] | ||
class Category | ||
{ | ||
use ArchivableEntity; | ||
use SluggableTrait; | ||
|
||
#[ORM\Id] | ||
#[ORM\Column(type: UuidType::NAME, unique: true)] | ||
#[ORM\GeneratedValue(strategy: 'CUSTOM')] | ||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] | ||
private ?Uuid $id = null; | ||
|
||
#[ORM\Column(length: 255, nullable: true)] | ||
private ?string $name = null; | ||
|
||
#[ORM\Column(type: 'datetime_immutable')] | ||
private ?\DateTimeImmutable $createdAt = null; | ||
|
||
#[ORM\Column(nullable: true, type: 'datetime_immutable')] | ||
private ?\DateTimeImmutable $updatedAt = null; | ||
|
||
#[ORM\ManyToMany(targetEntity: Project::class, inversedBy: 'categories', cascade: ['persist'], fetch: 'EAGER', orphanRemoval: true)] | ||
private Collection $projects; | ||
|
||
public function __construct() | ||
{ | ||
$this->projects = new ArrayCollection(); | ||
} | ||
|
||
final public function getId(): ?Uuid | ||
{ | ||
return $this->id; | ||
} | ||
|
||
final public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
final public function setName(?string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
final public function getCreatedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->createdAt; | ||
} | ||
|
||
final public function setCreatedAt(\DateTimeImmutable $createdAt): self | ||
{ | ||
$this->createdAt = $createdAt; | ||
|
||
return $this; | ||
} | ||
|
||
final public function getUpdatedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->updatedAt; | ||
} | ||
|
||
final public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self | ||
{ | ||
$this->updatedAt = $updatedAt; | ||
|
||
return $this; | ||
} | ||
|
||
#[ORM\PrePersist] | ||
final public function setCreatedAtValue(): void | ||
{ | ||
$this->createdAt = new \DateTimeImmutable(); | ||
} | ||
|
||
#[ORM\PreUpdate] | ||
final public function setUpdatedAtValue(): void | ||
{ | ||
$this->updatedAt = new \DateTimeImmutable(); | ||
} | ||
|
||
final public function getProjects(): Collection | ||
{ | ||
return $this->projects; | ||
} | ||
|
||
final public function addProject(Project $project): self | ||
{ | ||
!$this->projects->contains($project) | ||
&& $this->projects->add($project); | ||
|
||
return $this; | ||
} | ||
|
||
final public function removeProject(Project $project): self | ||
{ | ||
$this->projects->removeElement($project); | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.