feat/ajout-de-fonctionnalites (#1)
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
Reviewed-on: #1 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #1.
This commit is contained in:
189
src/Entity/Application.php
Normal file
189
src/Entity/Application.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?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 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')",
|
||||
),
|
||||
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<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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user