<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
#[ORM\Entity]
#[ApiResource(
iri: 'DemandUpload',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'demand_upload:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'demand_upload:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'demand_upload:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['demand_upload:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'demand_upload:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'demand_upload:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'demand' => 'exact',
'uploadType' => 'exact',
// 'year' => 'start',
'createdAt' => 'start',
])]
#[ApiFilter(OrderFilter::class, properties: [
'uploadType',
// 'year',
'createdAt'
])]
class DemandUpload
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups([
'demand_upload:collection:get',
'demand_upload:collection:post',
'demand_upload:item:get',
'demand_upload:item:put',
])]
private ?int $id = null;
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Assert\Type('string')]
#[Groups([
'demand_upload:collection:get',
'demand_upload:collection:post',
'demand_upload:item:get',
'demand_upload:item:put',
'demand:item:get',
])]
private ?string $uploadType = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[ApiProperty()]
#[Groups([
'demand_upload:collection:get',
'demand_upload:collection:post',
'demand_upload:item:get',
'demand_upload:item:put',
'demand:item:get',
])]
private ?int $year = null;
#[ORM\ManyToOne(targetEntity: Demand::class, inversedBy: 'uploads')]
#[Groups([
'demand_upload:collection:get',
'demand_upload:collection:post',
'demand_upload:item:get',
'demand_upload:item:put',
])]
private $demand;
#[ORM\OneToOne(inversedBy: 'demandUpload', targetEntity: Media::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[Groups([
'demand_upload:collection:get',
'demand_upload:collection:post',
'demand_upload:item:get',
'demand_upload:item:put',
'demand:item:get',
])]
private $upload;
public function getId(): ?int
{
return $this->id;
}
/**
* @param string|null $uploadType
*/
public function setUploadType($uploadType): void
{
$this->uploadType = $uploadType;
}
public function getUploadType(): ?string
{
return $this->uploadType;
}
public function setYear(?int $year): void
{
$this->year = $year;
}
public function getYear(): ?int
{
return $this->year;
}
public function getDemand(): ?Demand
{
return $this->demand;
}
public function setDemand(?Demand $demand): self
{
$this->demand = $demand;
return $this;
}
public function getUpload(): ?Media
{
return $this->upload;
}
public function setUpload(?Media $upload): self
{
$this->upload = $upload;
return $this;
}
}