Moving api requests to another controller.
This commit is contained in:
@@ -8,7 +8,6 @@ use App\Form\BookType;
|
||||
use App\Form\FileType;
|
||||
use App\Form\SearchType;
|
||||
use App\Repository\BookRepository;
|
||||
use App\Repository\FileRepository;
|
||||
use App\Service\FileService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
@@ -17,7 +16,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Techtube\Bookinfo\BookFinder;
|
||||
|
||||
#[Route('/book')]
|
||||
class BookController extends AbstractController
|
||||
@@ -73,21 +71,19 @@ 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('/search/', name: 'app_book_search_book', methods: ['GET', 'POST'])]
|
||||
#[Route('/search/', name: 'app_book_search', methods: ['GET', 'POST'])]
|
||||
public function searchBook(BookRepository $bookRepository, Request $request): Response
|
||||
{
|
||||
$searchForm = $this->createForm(SearchType::class);
|
||||
$searchForm->handleRequest($request);
|
||||
$books = [];
|
||||
|
||||
if ($searchForm->isSubmitted() && $searchForm->isValid()) {
|
||||
$books = $bookRepository->findByTitle($searchForm->get('search')->getData());
|
||||
return $this->redirectToRoute('app_book_search', ['search' => ($searchForm->get('search')->getData())]);
|
||||
}
|
||||
|
||||
if ($request->query->has('search')) {
|
||||
$books = $bookRepository->findByTitle($request->query->get('search'));
|
||||
}
|
||||
return $this->renderForm('book/search.html.twig', [
|
||||
'books' => $books,
|
||||
@@ -95,18 +91,10 @@ class BookController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[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', 'POST'])]
|
||||
public function show(
|
||||
Book $book,
|
||||
Request $request,
|
||||
FileRepository $fileRepository,
|
||||
FileService $fileService
|
||||
): Response {
|
||||
$fileForm = $this->createForm(FileType::class);
|
||||
@@ -136,7 +124,6 @@ class BookController extends AbstractController
|
||||
Request $request,
|
||||
Book $book,
|
||||
BookRepository $bookRepository,
|
||||
FileRepository $fileRepository,
|
||||
FileService $fileService
|
||||
): Response {
|
||||
$form = $this->createForm(BookType::class, $book);
|
||||
|
||||
25
src/Controller/OnlineSourceController.php
Normal file
25
src/Controller/OnlineSourceController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Techtube\Bookinfo\BookFinder;
|
||||
|
||||
#[Route('/online')]
|
||||
class OnlineSourceController extends AbstractController
|
||||
{
|
||||
#[Route('/search/{phrase}', name: 'app_online_search', methods: ['GET'])]
|
||||
public function search(string $phrase, BookFinder $bookFinder): JsonResponse
|
||||
{
|
||||
return new JsonResponse($bookFinder->search($phrase));
|
||||
}
|
||||
|
||||
#[Route('/info/{urlInBase64}', name: 'app_online_info', methods: ['GET'])]
|
||||
public function info(string $urlInBase64, BookFinder $bookFinder): JsonResponse
|
||||
{
|
||||
return new JsonResponse($bookFinder->byUrl(base64_decode($urlInBase64)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class SearchType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->setAction($this->router->generate('app_book_search_book'))
|
||||
->setAction($this->router->generate('app_book_search'))
|
||||
->add('search', TextType::class, ['attr' => ['placeholder' => 'Book title']])
|
||||
;
|
||||
}
|
||||
@@ -28,7 +28,6 @@ class SearchType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
// Configure your form options here
|
||||
'attr' => ['class' => 'd-flex']
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user