From 82169b254c7cef17d513f13e65d127e888e51128 Mon Sep 17 00:00:00 2001 From: tristan Date: Mon, 6 Apr 2026 13:29:01 +0200 Subject: [PATCH] feat : add Application entity with API Platform resource Co-Authored-By: Claude Sonnet 4.6 --- src/Entity/Application.php | 189 +++++++++++++++++++++++ src/Repository/ApplicationRepository.php | 20 +++ 2 files changed, 209 insertions(+) create mode 100644 src/Entity/Application.php create mode 100644 src/Repository/ApplicationRepository.php diff --git a/src/Entity/Application.php b/src/Entity/Application.php new file mode 100644 index 0000000..dbac593 --- /dev/null +++ b/src/Entity/Application.php @@ -0,0 +1,189 @@ + ['app:read']], + security: "is_granted('ROLE_ADMIN')", + ), + new Get( + uriVariables: ['slug'], + normalizationContext: ['groups' => ['app:read', 'app:detail']], + security: "is_granted('ROLE_ADMIN')", + ), + new Post( + security: "is_granted('ROLE_ADMIN')", + ), + new Patch( + uriVariables: ['slug'], + security: "is_granted('ROLE_ADMIN')", + ), + new Delete( + uriVariables: ['slug'], + security: "is_granted('ROLE_ADMIN')", + ), + ], + normalizationContext: ['groups' => ['app:read']], + denormalizationContext: ['groups' => ['app:write']], +)] +#[ORM\Entity(repositoryClass: ApplicationRepository::class)] +class Application +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + #[Groups(['app:read'])] + private ?int $id = null; + + #[ORM\Column(length: 255)] + #[Groups(['app:read', 'app:write'])] + private ?string $name = null; + + #[ORM\Column(length: 255, unique: true)] + #[ApiProperty(identifier: true)] + #[Groups(['app:read', 'app:write'])] + private ?string $slug = null; + + #[ORM\Column(length: 255)] + #[Groups(['app:read', 'app:write'])] + private ?string $registryImage = null; + + #[ORM\Column(type: Types::TEXT, nullable: true)] + #[Groups(['app:read', 'app:write'])] + private ?string $description = null; + + #[ORM\Column(length: 255, nullable: true)] + #[Groups(['app:read', 'app:write'])] + private ?string $giteaUrl = null; + + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] + #[Groups(['app:read'])] + private ?DateTimeImmutable $createdAt = null; + + /** @var Collection */ + #[ORM\OneToMany(targetEntity: Environment::class, mappedBy: 'application', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[Groups(['app:detail'])] + private Collection $environments; + + public function __construct() + { + $this->createdAt = new DateTimeImmutable(); + $this->environments = 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 getSlug(): ?string + { + return $this->slug; + } + + public function setSlug(string $slug): static + { + $this->slug = $slug; + + return $this; + } + + public function getRegistryImage(): ?string + { + return $this->registryImage; + } + + public function setRegistryImage(string $registryImage): static + { + $this->registryImage = $registryImage; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): static + { + $this->description = $description; + + return $this; + } + + public function getGiteaUrl(): ?string + { + return $this->giteaUrl; + } + + public function setGiteaUrl(?string $giteaUrl): static + { + $this->giteaUrl = $giteaUrl; + + return $this; + } + + public function getCreatedAt(): ?DateTimeImmutable + { + return $this->createdAt; + } + + /** @return Collection */ + public function getEnvironments(): Collection + { + return $this->environments; + } + + public function addEnvironment(Environment $environment): static + { + if (!$this->environments->contains($environment)) { + $this->environments->add($environment); + $environment->setApplication($this); + } + + return $this; + } + + public function removeEnvironment(Environment $environment): static + { + if ($this->environments->removeElement($environment)) { + if ($environment->getApplication() === $this) { + $environment->setApplication(null); + } + } + + return $this; + } +} diff --git a/src/Repository/ApplicationRepository.php b/src/Repository/ApplicationRepository.php new file mode 100644 index 0000000..c37e1f8 --- /dev/null +++ b/src/Repository/ApplicationRepository.php @@ -0,0 +1,20 @@ + + */ +class ApplicationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Application::class); + } +}