From 0621388ee6153480f93dfa6d331d392146932eca Mon Sep 17 00:00:00 2001 From: matthieu Date: Mon, 9 Mar 2026 22:37:32 +0100 Subject: [PATCH] feat : add Client entity with CRUD API Co-Authored-By: Claude Opus 4.6 --- migrations/Version20260309213629.php | 31 ++++++ src/Entity/Client.php | 155 +++++++++++++++++++++++++++ src/Repository/ClientRepository.php | 17 +++ 3 files changed, 203 insertions(+) create mode 100644 migrations/Version20260309213629.php create mode 100644 src/Entity/Client.php create mode 100644 src/Repository/ClientRepository.php diff --git a/migrations/Version20260309213629.php b/migrations/Version20260309213629.php new file mode 100644 index 0000000..c487c62 --- /dev/null +++ b/migrations/Version20260309213629.php @@ -0,0 +1,31 @@ +addSql('CREATE TABLE client (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) DEFAULT NULL, phone VARCHAR(50) DEFAULT NULL, street VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, postal_code VARCHAR(20) DEFAULT NULL, PRIMARY KEY (id))'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE client'); + } +} diff --git a/src/Entity/Client.php b/src/Entity/Client.php new file mode 100644 index 0000000..41e7551 --- /dev/null +++ b/src/Entity/Client.php @@ -0,0 +1,155 @@ + ['client:read']], + denormalizationContext: ['groups' => ['client:write']], + order: ['name' => 'ASC'], +)] +#[ORM\Entity(repositoryClass: ClientRepository::class)] +class Client +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + #[Groups(['client:read', 'project:read'])] + private ?int $id = null; + + #[ORM\Column(length: 255)] + #[Groups(['client:read', 'client:write', 'project:read'])] + private ?string $name = null; + + #[ORM\Column(length: 255, nullable: true)] + #[Groups(['client:read', 'client:write'])] + private ?string $email = null; + + #[ORM\Column(length: 50, nullable: true)] + #[Groups(['client:read', 'client:write'])] + private ?string $phone = null; + + #[ORM\Column(length: 255, nullable: true)] + #[Groups(['client:read', 'client:write'])] + private ?string $street = null; + + #[ORM\Column(length: 255, nullable: true)] + #[Groups(['client:read', 'client:write'])] + private ?string $city = null; + + #[ORM\Column(length: 20, nullable: true)] + #[Groups(['client:read', 'client:write'])] + private ?string $postalCode = null; + + /** @var Collection */ + #[ORM\OneToMany(targetEntity: Project::class, mappedBy: 'client')] + private Collection $projects; + + public function __construct() + { + $this->projects = 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 getEmail(): ?string + { + return $this->email; + } + + public function setEmail(?string $email): static + { + $this->email = $email; + + return $this; + } + + public function getPhone(): ?string + { + return $this->phone; + } + + public function setPhone(?string $phone): static + { + $this->phone = $phone; + + return $this; + } + + public function getStreet(): ?string + { + return $this->street; + } + + public function setStreet(?string $street): static + { + $this->street = $street; + + return $this; + } + + public function getCity(): ?string + { + return $this->city; + } + + public function setCity(?string $city): static + { + $this->city = $city; + + return $this; + } + + public function getPostalCode(): ?string + { + return $this->postalCode; + } + + public function setPostalCode(?string $postalCode): static + { + $this->postalCode = $postalCode; + + return $this; + } + + /** @return Collection */ + public function getProjects(): Collection + { + return $this->projects; + } +} diff --git a/src/Repository/ClientRepository.php b/src/Repository/ClientRepository.php new file mode 100644 index 0000000..198e9d2 --- /dev/null +++ b/src/Repository/ClientRepository.php @@ -0,0 +1,17 @@ +