diff --git a/assets/js/book.js b/assets/js/book.js
index d6395f3..1f7161a 100644
--- a/assets/js/book.js
+++ b/assets/js/book.js
@@ -1,6 +1,8 @@
import Vue from 'vue';
import Book from './pages/book'
+import BookListing from './pages/booklisting'
Vue.component('Book', Book);
+Vue.component('BookListing', BookListing);
new Vue().$mount('#app');
\ No newline at end of file
diff --git a/assets/js/pages/booklisting.vue b/assets/js/pages/booklisting.vue
new file mode 100644
index 0000000..212a967
--- /dev/null
+++ b/assets/js/pages/booklisting.vue
@@ -0,0 +1,69 @@
+
+
+
+
+
+ |
+ Title |
+ Description |
+ Rating |
+ Publisher |
+ Publish date |
+ Actions |
+
+
+
+
+
+
+
+
+ |
+ {{ book.title }} |
+ {{ book.short_description }} |
+ {{ '⭐'.repeat(book.rating) }} |
+ {{ book.publisher }} |
+ {{ book.publish_date }} |
+
+ show
+ edit
+ |
+
+
+ | no records found |
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php
index 0626f3a..257b52a 100644
--- a/src/Controller/BookController.php
+++ b/src/Controller/BookController.php
@@ -20,10 +20,15 @@ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
class BookController extends AbstractController
{
#[Route('/', name: 'app_book_index', methods: ['GET'])]
- public function index(BookRepository $bookRepository): Response
+ public function index(BookRepository $bookRepository, Request $request): Response
{
+ if ($request->query->has('search')) {
+ $books = $bookRepository->findByTitle($request->query->get('search'));
+ }
+
return $this->render('book/index.html.twig', [
- 'books' => $bookRepository->findAll(),
+ 'searchTerm' => $request->query->get('search'),
+ 'books' => $books ?? $bookRepository->findAll(),
]);
}
diff --git a/src/Entity/Book.php b/src/Entity/Book.php
index 95d6398..94b9d27 100644
--- a/src/Entity/Book.php
+++ b/src/Entity/Book.php
@@ -11,7 +11,10 @@ use App\Repository\BookRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Annotation\Groups;
+use Symfony\Component\Serializer\Annotation\SerializedName;
+use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
#[ApiResource]
#[ORM\Entity(repositoryClass: BookRepository::class)]
@@ -38,6 +41,7 @@ class Book
private $publisher;
#[ORM\Column(type: 'date', nullable: true)]
+ #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private $publish_date;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
@@ -116,6 +120,12 @@ class Book
return $this->description;
}
+ #[SerializedName('short_description')]
+ public function getShortDescription(): ?string
+ {
+ return mb_strimwidth($this->description, 0, 150, "...");;
+ }
+
public function setDescription(?string $description): self
{
$this->description = $description;
diff --git a/templates/book/index.html.twig b/templates/book/index.html.twig
index 7a370d6..a741afc 100644
--- a/templates/book/index.html.twig
+++ b/templates/book/index.html.twig
@@ -5,7 +5,11 @@
{% block body %}
-
Book list
+ {% if(searchTerm) %}
+ Book search: {{ searchTerm }}
+ {% else %}
+ Book list
+ {% endif %}
-
-
-
- |
- Title |
- Description |
- Rating |
- Publisher |
- Publish date |
- actions |
-
-
-
- {% for book in books %}
-
-
- {% if file_exists(asset('book_covers/cover_' ~ book.id ~ '.jpg')) %}
-
-
- {% endif %}
- |
- {{ book.title }} |
- {{ book.description | slice(0, 200) }} |
- {% if book.rating %}{% for i in range(1, book.rating) %}⭐{% endfor %}{% endif %} |
- {{ book.publisher }} |
- {{ book.publishDate ? book.publishDate|date('Y-m-d') : '' }} |
-
- show
- edit
- |
-
- {% else %}
-
- | no records found |
-
- {% endfor %}
-
-
+
+
+
+
{% endblock %}
+
+{% block javascripts %}
+ {{ encore_entry_script_tags('book') }}
+{% endblock %}
\ No newline at end of file