<?php
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\ApiResources\State\Provider\Media\Base64DownloadProvider;
use App\Application\Controller\Api\Media\DownloadAction;
use App\Application\Controller\Api\Media\RotateMediaAction;
use App\Application\Controller\Api\Media\UploadAction;
use App\Domain\Entity\Behavior\Identifiable;
use App\Domain\Entity\Behavior\Uploadable;
use DateTime;
use Gedmo\Timestampable\Traits\Timestampable;
use Symfony\Component\HttpFoundation\File\File;
/**
* Class Media
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations: [
new Delete(security: "is_granted('ROLE_ADMIN') or object.author.id == user.id"),
new Get(),
new GetCollection(),
new Post(
controller: UploadAction::class,
openapiContext: [
'summary' => 'Upload Media',
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary',
],
'filters' => [
'type' => 'integer',
'format' => 'integer',
],
],
],
'example' => [
'file' => 'Mon fichier',
'filters' => 7,
],
],
],
],
],
deserialize: false
),
new Get(uriTemplate: '/media/{uuid}/download', controller: DownloadAction::class),
new Get(uriTemplate: '/media/{uuid}/download.base64', provider: Base64DownloadProvider::class),
new Put(
uriTemplate: '/media/{uuid}/rotate',
controller: RotateMediaAction::class,
security: "is_granted('ROLE_ADMIN')",
),
],
normalizationContext: ['groups' => ['media_read']],
denormalizationContext: ['groups' => ['media_write']]
)]
class Media
{
use Identifiable;
use Timestampable;
use Uploadable;
/**
* @var Person|null
*/
public ?Person $author;
public ?string $personRemoteId = null;
public ?string $remoteId = null;
public ?bool $remoteMain = null;
public ?DateTime $zhistUpdate = null;
/**
* Media constructor.
*
* @param Person|null $author
* @param File|null $file
* @param string|null $contentUrl
* @param string|null $filePath
* @param string|null $fileSize
* @param string|null $mimeType
* @param string|null $originalName
* @param int $filters
*/
public function __construct(
?Person $author = null,
?File $file = null,
?string $contentUrl = null,
?string $filePath = null,
?string $fileSize = null,
?string $mimeType = null,
?string $originalName = null,
public int $filters = -1,
) {
$this->file = $file;
$this->contentUrl = $contentUrl;
$this->filePath = $filePath;
$this->fileSize = $fileSize;
$this->mimeType = $mimeType;
$this->originalName = $originalName;
$this->author = $author;
}
}