<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\CreateMediaObjectAction;
use App\Repository\AlbumRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Vich\Uploadable
*/
#[ORM\Entity(repositoryClass: AlbumRepository::class)]
#[ApiResource(
iri: 'http://schema.org/Albums',
normalizationContext: ['groups' => ['media_object:read']],
itemOperations: ['get'],
collectionOperations: [
'get',
'post' => [
'controller' => CreateMediaObjectAction::class,
'deserialize' => false,
'validation_groups' => ['Default', 'media_object_create'],
'openapi_context' => [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary',
],
],
],
],
],
],
],
],
]
)]
class Album
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['pitch:read'])]
private $id;
#[Groups(['media_object:read','pitch:read','favoris:read','reservation:read'])]
public $url;
#[ORM\Column(type: 'string', length: 100)]
#[Groups(['media_object:read','pitch:read','favoris:read','reservation:read'])]
private $name;
/**
* @Vich\UploadableField(mapping="albums_pitch", fileNameProperty="name")
*/
#[Assert\NotNull(groups: ['media_object_create'])]
public ?File $file = null;
#[ORM\ManyToOne(targetEntity: Pitch::class, inversedBy: 'albums',cascade:["persist"])]
private $pitch;
public function getId(): ?int
{
return $this->id;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPitch(): ?Pitch
{
return $this->pitch;
}
public function setPitch(?Pitch $pitch): self
{
$this->pitch = $pitch;
return $this;
}
}