43 lines
1,022 B
PHP
43 lines
1,022 B
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Link;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity]
|
|
#[ApiResource]
|
|
#[ApiResource(
|
|
shortName: 'BookAuthor',
|
|
uriTemplate: '/books/{bookId}/authors',
|
|
uriVariables: ['bookId' => new Link(fromClass: Book::class, fromProperty: 'author')],
|
|
operations: [
|
|
new GetCollection(),
|
|
new Get(),
|
|
],
|
|
security: "is_granted('ROLE_ADMIN')",
|
|
)]
|
|
class Author
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $name = null;
|
|
|
|
/** @var Collection<int, Book> */
|
|
#[ORM\OneToMany(targetEntity: Book::class, mappedBy: 'author')]
|
|
private Collection $books;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->books = new ArrayCollection();
|
|
}
|
|
}
|