<?php
namespace App\Containers\ServiceSection\TravelContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
// use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Containers\ServiceSection\TravelContainer\Data\Repositories\FileRepository;
use App\Containers\CrmSection\EquipmentContainer\Entities\ApplicationEntity;
#[ApiResource(
routePrefix: '/service',
normalizationContext: [
'groups' => ['travel:read', 'file:travel:read', 'read'],
'enable_max_depth' => true
],
denormalizationContext: [
'groups' => ['file:travel:create', 'file:travel:update']
],
types: ['https://schema.org/MediaObject'],
operations: [
new Get(
uriTemplate: '/travel_files/{id}', requirements: ['id' => '\d+'],
validationContext: ['groups' => ['file:travel:read']],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new GetCollection(
uriTemplate: '/travel_files',
validationContext: ['groups' => ['file:travel:read']],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'Service_Travels'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class)]
#[ORM\Entity(repositoryClass: FileRepository::class)]
#[ORM\Table(name: '`service_travels_files`')]
#[Vich\Uploadable]
class FileEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read', 'file:travel:read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 20, nullable: false)]
#[Assert\Length(min: 0, max: 20, groups: ['file:travel:update', 'file:travel:create'])]
#[Groups(['file:travel:read', 'file:travel:update', 'file:travel:create'])]
#[ApiProperty(security: "is_granted('ROLE_ADMIN')")]
private string $extStartTimestamp;
#[ORM\Column(type: Types::STRING, length: 20, nullable: false)]
#[Assert\Length(min: 0, max: 20, groups: ['file:travel:update', 'file:travel:create'])]
#[Groups(['file:travel:read', 'file:travel:update', 'file:travel:create'])]
#[ApiProperty(security: "is_granted('ROLE_ADMIN')")]
private string $extEndTimestamp;
#[ORM\ManyToOne(targetEntity: ApplicationEntity::class)]
#[ORM\JoinColumn(name: 'application_id', referencedColumnName: 'id', nullable: false)]
#[Assert\NotNull(groups: ['file:travel:update', 'file:travel:create'])]
#[Assert\NotBlank(groups: ['file:travel:update', 'file:travel:create'])]
#[Groups(['file:travel:read', 'file:travel:update', 'file:travel:create'])]
#[MaxDepth(1)]
private ApplicationEntity $application;
#[ApiProperty(types: ['https://schema.org/contentUrl'])]
#[Groups(['read', 'file:travel:read'])]
public ?string $contentUrl = null;
#[Vich\UploadableField(mapping: 'travels_object', fileNameProperty: 'filePath')]
#[Assert\NotNull(groups: ['file:travel:read', 'file:travel:update', 'file:travel:create'])]
public ?File $file = null;
#[ORM\Column(nullable: true)]
public ?string $filePath = null;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private $updatedAt;
public function getId(): ?int
{
return $this->id;
}
public function getExtStartTimestamp(): ?string
{
return $this->extStartTimestamp;
}
public function setExtStartTimestamp($value): ?self
{
$this->extStartTimestamp = $value;
return $this;
}
public function getExtEndTimestamp(): ?string
{
return $this->extEndTimestamp;
}
public function setExtEndTimestamp($value): ?self
{
$this->extEndTimestamp = $value;
return $this;
}
public function getApplication(): ?ApplicationEntity
{
return $this->application;
}
public function setApplication($application): ?self
{
$this->application = $application;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
}