diff --git a/assets/js/pages/files.vue b/assets/js/pages/files.vue index 3e80002..e5523bc 100644 --- a/assets/js/pages/files.vue +++ b/assets/js/pages/files.vue @@ -69,13 +69,17 @@ export default { return (bytes / Math.pow(1024, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + 'B'; }, getFiles: function () { - axios.get(this.getFilesEndpoint()).then(response => this.files = response.data) + axios.get(this.getFilesEndpoint(), { + headers: { + 'accept': 'application/json' + } + }).then(response => this.files = response.data) }, getFilesEndpoint: function () { if (this.bookId) { - return '/book/' + this.bookId + '/files'; + return `/api/books/${this.bookId}/files`; } - return '/file/all'; + return `/api/files`; } } } diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php index 0f3cd40..0626f3a 100644 --- a/src/Controller/BookController.php +++ b/src/Controller/BookController.php @@ -111,13 +111,6 @@ class BookController extends AbstractController ]); } - #[Route('/{id}/files', name: 'app_book_file', methods: ['GET'])] - public function files(Book $book): JsonResponse - { - return $this->json($book->getFiles(), context: [AbstractNormalizer::IGNORED_ATTRIBUTES => ['book']]); - } - - #[Route('/{id}/edit', name: 'app_book_edit', methods: ['GET', 'POST'])] public function edit( Request $request, diff --git a/src/Entity/Book.php b/src/Entity/Book.php index e393b27..dc2c8da 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -2,11 +2,14 @@ namespace App\Entity; +use ApiPlatform\Core\Annotation\ApiResource; +use ApiPlatform\Core\Annotation\ApiSubresource; use App\Repository\BookRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +#[ApiResource] #[ORM\Entity(repositoryClass: BookRepository::class)] class Book { @@ -33,6 +36,7 @@ class Book #[ORM\Column(type: 'string', length: 255, nullable: true)] private $subtitle; + #[ApiSubresource] #[ORM\OneToMany(mappedBy: 'book', targetEntity: File::class, orphanRemoval: true)] private $files; diff --git a/templates/book/index.html.twig b/templates/book/index.html.twig index e5834aa..7a370d6 100644 --- a/templates/book/index.html.twig +++ b/templates/book/index.html.twig @@ -19,6 +19,7 @@
{{ book.author }}
-{% for i in range(1, book.rating) %}⭐{% endfor %}
+{% if book.rating %}{% for i in range(1, book.rating) %}⭐{% endfor %}{% endif %}