renamed 'search' to 'app_search' in router

This commit is contained in:
ZeKap 2024-02-22 09:05:55 +01:00
parent b68d533bac
commit c838a3d2ed
No known key found for this signature in database
GPG Key ID: 8D70E0631DD5792A
2 changed files with 50 additions and 52 deletions

View File

@ -11,7 +11,8 @@ use GuzzleHttp\Client;
class SearchController extends AbstractController class SearchController extends AbstractController
{ {
private static function makeRequest(string $method,string $endpoint, array $querryParams){ private static function makeRequest(string $method, string $endpoint, array $querryParams)
{
// Create a new Guzzle HTTP client // Create a new Guzzle HTTP client
$baseUri = 'https://api.discogs.com/'; $baseUri = 'https://api.discogs.com/';
@ -19,35 +20,35 @@ class SearchController extends AbstractController
'base_uri' => $baseUri, 'base_uri' => $baseUri,
'timeout' => 2.0, // You can set request timeout (in seconds) 'timeout' => 2.0, // You can set request timeout (in seconds)
]); ]);
// Set the base URI for the request and any default request options // Set the base URI for the request and any default request options
$auth = array( $auth = array(
"key" => "kLzxeHuJCXRyQuBURaEN", "key" => "kLzxeHuJCXRyQuBURaEN",
"secret" => "biDCkuoMbGLeDtQGqCPCtbVqmzPaVmQG" "secret" => "biDCkuoMbGLeDtQGqCPCtbVqmzPaVmQG"
); );
// Create the query parameters array // Create the query parameters array
$querryParams = array_merge($querryParams, $auth); $querryParams = array_merge($querryParams, $auth);
// Send a GET request to the specified URI with the query parameters // Send a GET request to the specified URI with the query parameters
$response = $client->request($method, "/database/".$endpoint, [ $response = $client->request($method, "/database/" . $endpoint, [
'query' => $querryParams 'query' => $querryParams
]); ]);
// Get the status code of the response // Get the status code of the response
$statusCode = $response->getStatusCode(); $statusCode = $response->getStatusCode();
// Get the body of the response // Get the body of the response
$body = $response->getBody()->getContents(); $body = $response->getBody()->getContents();
return json_decode($body,true); return json_decode($body, true);
} }
#[Route('/search', name: 'search')] #[Route('/search', name: 'app_search')]
public function index(Request $request): Response public function index(Request $request): Response
{ {
$page = $request->query->get('page'); $page = $request->query->get('page');
$result = SearchController::makeRequest("GET","search",[ $result = SearchController::makeRequest("GET", "search", [
"q" => $request->query->get('q'), "q" => $request->query->get('q'),
"type" => "release", "type" => "release",
"page" => strval($page), "page" => strval($page),
@ -57,9 +58,9 @@ class SearchController extends AbstractController
return $this->render('search/search.html.twig', [ return $this->render('search/search.html.twig', [
'controller_name' => 'SearchController', 'controller_name' => 'SearchController',
'query' => $request->query->get('q'), 'query' => $request->query->get('q'),
'page' => $request->query->get('page'), 'page' => $request->query->get('page'),
"next_page" => $page < $result["pagination"]["pages"] ? strval($page + 1) : strval($page), "next_page" => $page < $result["pagination"]["pages"] ? strval($page + 1) : strval($page),
"previous_page" => $page >1 ? strval($page - 1) : strval($page), "previous_page" => $page > 1 ? strval($page - 1) : strval($page),
'results' => $result["results"] 'results' => $result["results"]
]); ]);
} }

View File

@ -1,42 +1,39 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>{% block title %}{{app.title}}{% endblock %}</title> <title>{% block title %}{{app.title}}{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>"> <link
{% block stylesheets %} rel="icon"
<link rel="stylesheet" href="{{ asset('styles/app.css') }}"/> href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>"
<link rel="stylesheet" href="{{ asset('styles/fonts.css') }}"/> />
{% endblock %} {% block stylesheets %}
<link rel="stylesheet" href="{{ asset('styles/app.css') }}" />
{% block javascripts %} <link rel="stylesheet" href="{{ asset('styles/fonts.css') }}" />
{% block importmap %}{{ importmap('app') }}{% endblock %} {% endblock %} {% block javascripts %} {% block importmap %}{{
{% endblock %} importmap('app') }}{% endblock %} {% endblock %}
</head> </head>
<body> <body>
{% block header %} {% block header %}
<header> <header>
<a href="{{url('index')}}">Frutti</a> <a href="{{url('index')}}">Frutti</a>
<form action="{{url('search')}}" method="get"> <form action="{{url('app_search')}}" method="get">
<input type="text" name="q" id="q" placeholder="Search"> <input type="text" name="q" id="q" placeholder="Search" />
<label> <label>
<input type="submit" value="search"> <input type="submit" value="search" />
<img src="{{ asset('/styles/search.svg') }}" alt="Search"> <img src="{{ asset('/styles/search.svg') }}" alt="Search" />
</label> </label>
</form> </form>
<a href="{{url('app_login')}}" class="button-link">Connect</a> <a href="{{url('app_login')}}" class="button-link">Connect</a>
</header> </header>
{% endblock %} {% endblock %}
<main> <main>{% block body %}{% endblock %}</main>
{% block body %}{% endblock %}
</main> {% block footer %}
<footer>
<p>Done by: Capelier 🏳️‍⚧️ — Rubini 💅 — Simaila 🤓</p>
{% block footer %} </footer>
<footer> {% endblock %}
<p>Done by: Capelier 🏳️‍⚧️ — Rubini 💅 — Simaila 🤓</p> </body>
</footer>
{% endblock %}
</body>
</html> </html>