193 lines
4.8 KiB
PHP
193 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Delete;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use App\Repository\ApplicationRepository;
|
|
use App\State\ApplicationProvider;
|
|
use DateTimeImmutable;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
|
|
#[ApiResource(
|
|
operations: [
|
|
new GetCollection(
|
|
normalizationContext: ['groups' => ['app:read']],
|
|
security: "is_granted('ROLE_ADMIN')",
|
|
provider: ApplicationProvider::class,
|
|
),
|
|
new Get(
|
|
uriVariables: ['slug'],
|
|
normalizationContext: ['groups' => ['app:read', 'app:detail']],
|
|
security: "is_granted('ROLE_ADMIN')",
|
|
provider: ApplicationProvider::class,
|
|
),
|
|
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<int, Environment> */
|
|
#[ORM\OneToMany(targetEntity: Environment::class, mappedBy: 'application', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
|
#[Groups(['app:read', '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<int, Environment> */
|
|
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;
|
|
}
|
|
}
|