Added vue handling the information from lubimy czytac to fetch information about the books and fill in the form automatically.
This commit is contained in:
@@ -9,9 +9,12 @@ use App\Repository\BookRepository;
|
||||
use App\Repository\FileRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Techtube\Bookinfo\BookFinder;
|
||||
use Techtube\Bookinfo\DataParser;
|
||||
|
||||
#[Route('/book')]
|
||||
class BookController extends AbstractController
|
||||
@@ -34,12 +37,20 @@ class BookController extends AbstractController
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$bookRepository->add($book, true);
|
||||
|
||||
$cover = $request->files->get('book')['cover'];
|
||||
if ($cover) {
|
||||
$cover->move(
|
||||
$this->getParameter('book_covers'),
|
||||
'cover_' . $book->getId() . '.' . $cover->guessClientExtension()
|
||||
$bookRequest = $request->request->all('book');
|
||||
if (!empty($bookRequest['cover_url'])) {
|
||||
file_put_contents(
|
||||
$this->getParameter('book_covers') . 'cover_' . $book->getId() . '.jpg',
|
||||
file_get_contents($bookRequest['cover_url'])
|
||||
);
|
||||
} else {
|
||||
$cover = $request->files->get('book')['cover'];
|
||||
if ($cover) {
|
||||
$cover->move(
|
||||
$this->getParameter('book_covers'),
|
||||
'cover_' . $book->getId() . '.' . $cover->guessClientExtension()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$ebook = $request->files->get('book')['ebook'];
|
||||
@@ -59,6 +70,20 @@ class BookController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/search/{phrase}', name: 'app_book_search', methods: ['GET'])]
|
||||
public function search(string $phrase): JsonResponse
|
||||
{
|
||||
$bookFinder = new BookFinder();
|
||||
return new JsonResponse($bookFinder->search($phrase));
|
||||
}
|
||||
|
||||
#[Route('/info/{urlInBase64}', name: 'app_book_info', methods: ['GET'])]
|
||||
public function info(string $urlInBase64): JsonResponse
|
||||
{
|
||||
$bookFinder = new BookFinder();
|
||||
return new JsonResponse($bookFinder->byUrl(base64_decode($urlInBase64)));
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_book_show', methods: ['GET'])]
|
||||
public function show(Book $book): Response
|
||||
{
|
||||
|
||||
@@ -57,6 +57,9 @@ class Book
|
||||
#[ORM\Column(type: 'smallint', nullable: true)]
|
||||
private $rating;
|
||||
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
private $category;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->files = new ArrayCollection();
|
||||
@@ -252,4 +255,16 @@ class Book
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?string
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(?string $category): self
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ class BookType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('Title')
|
||||
->add('title')
|
||||
->add('subtitle')
|
||||
->add('author')
|
||||
->add('category', TextType::class, ['attr' => ['rows' => 1]])
|
||||
->add('isbn')
|
||||
->add('pages')
|
||||
->add('tags')
|
||||
@@ -51,7 +52,10 @@ class BookType extends AbstractType
|
||||
'required' => false,
|
||||
'attr' => ['accept' => ".pdf, .epub, .mobi"]
|
||||
])
|
||||
->add('cover', FileType::class, ['mapped' => false, 'data_class' => null, 'required' => false]);
|
||||
->add('cover', FileType::class, ['mapped' => false, 'data_class' => null, 'required' => false])
|
||||
->add('cover_url', TextType::class, ['mapped' => false, 'help' => 'Fill in the field with a link to a cover image to use it as a cover for the book.', 'label'=> 'Cover url', 'required' => false])
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
Reference in New Issue
Block a user