<?php
declare(strict_types=1);
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Application\Controller\Api\Award\ImportAction;
use App\Domain\Entity\Behavior\Identifiable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
/**
* Class CamperVan
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations : [
new Get(),
new GetCollection(filters: ['award.search_filter', 'soft_delete']),
new Post(
uriTemplate: '/awards/import',
controller : ImportAction::class,
security : "is_granted('ROLE_ADMIN')",
deserialize: false,
serialize : false,
),
new Post(security: "is_granted('ROLE_ADMIN')"),
new Put(security: "is_granted('ROLE_ADMIN')"),
new Delete(),
],
normalizationContext : ['groups' => ['award_read']],
denormalizationContext: ['groups' => ['award_write']],
filters : ['award.search_filter'],
order : ['year' => 'DESC']
)]
class Award
{
use Identifiable;
use SoftDeleteable;
/**
* @var ArrayCollection
*/
public Collection $pointOfInterests;
/**
* @param string $code
* @param string $year
* @param Media|null $picture
*/
public function __construct(
public string $code,
public string $year,
public ?Media $picture = null,
) {
$this->pointOfInterests = new ArrayCollection();
}
/**
* @return Collection
*/
public function getPointOfInterests(): Collection
{
return $this->pointOfInterests;
}
/**
* @return int
*/
public function getPointOfInterestCount(): int
{
return $this->pointOfInterests->count();
}
/**
* @param Collection $pointOfInterests
*/
public function setPointOfInterests(Collection $pointOfInterests): void
{
$this->pointOfInterests = $pointOfInterests;
}
public function addPointOfInterest(PointOfInterest $pointOfInterest): void
{
if ($this->pointOfInterests->contains($pointOfInterest)) {
return;
}
$this->pointOfInterests->add($pointOfInterest);
$pointOfInterest->addAward($this);
}
public function removePointOfInterest(PointOfInterest $pointOfInterest): void
{
if (!$this->pointOfInterests->contains($pointOfInterest)) {
return;
}
$this->pointOfInterests->removeElement($pointOfInterest);
$pointOfInterest->removeAward($this);
}
}