diff --git a/browser.php b/browser.php
index 55d1c4d..f0ad083 100644
--- a/browser.php
+++ b/browser.php
@@ -7,6 +7,7 @@ use Krzysiej\RyobiCrawler\Controller\CategoryController;
use Krzysiej\RyobiCrawler\Controller\IndexController;
use Krzysiej\RyobiCrawler\Controller\ProductController;
use Krzysiej\RyobiCrawler\Controller\SearchController;
+use Krzysiej\RyobiCrawler\Controller\StarController;
use Krzysiej\RyobiCrawler\Models\Product;
use Twig\{Environment, Loader\FilesystemLoader};
use Symfony\Component\Routing\Matcher\UrlMatcher;
@@ -17,15 +18,17 @@ use Symfony\Component\Routing\RouteCollection;
if (!file_exists('database.sqlite')) {
exit('Database file database.sqlite missing. Run docker compose
docker compose exec php-app php index.php app:migrate
to create it.');
}
-$productRoute = new Route('browser.php/product/{product_id}', ['_controller' => ProductController::class], ['product_id' => '\d+']);
-$searchRoute = new Route('browser.php?search={search_term}', ['_controller' => SearchController::class]);
+$productRoute = new Route('/browser.php/product/{product_id}', ['_controller' => ProductController::class], ['product_id' => '\d+']);
+$searchRoute = new Route('/browser.php?search={search_term}', ['_controller' => SearchController::class]);
$categoryRoute = new Route('/browser.php/category/{category_name}', ['_controller' => CategoryController::class]);
-$indexRoute = new Route('browser.php', ['_controller' => IndexController::class]);
+$starRoute = new Route('/browser.php/star/{product_id}', ['_controller' => StarController::class]);
+$indexRoute = new Route('/browser.php', ['_controller' => IndexController::class]);
$routes = new RouteCollection();
$routes->add('product_show', $productRoute);
$routes->add('search_show', $searchRoute);
$routes->add('category_show', $categoryRoute);
+$routes->add('start_show', $starRoute);
$routes->add('index_show', $indexRoute);
$context = new RequestContext();
@@ -36,12 +39,10 @@ try {
die($e->getMessage());
}
-//dd($parameters['category_name']);
-
match ($parameters['_controller']) {
SearchController::class => (new $parameters['_controller']())($parameters['search_term']),
CategoryController::class => (new $parameters['_controller']())($parameters['category_name']),
- ProductController::class => (new $parameters['_controller']())($parameters['product_id']),
+ ProductController::class, StarController::class => (new $parameters['_controller']())($parameters['product_id']),
IndexController::class => (new $parameters['_controller']())(),
default => throw new Exception('Route not found')
};
diff --git a/src/Controller/StarController.php b/src/Controller/StarController.php
new file mode 100644
index 0000000..069437b
--- /dev/null
+++ b/src/Controller/StarController.php
@@ -0,0 +1,14 @@
+toggleStarred()->save();
+ header('Location: ' . $_SERVER['HTTP_REFERER']);
+ }
+}
diff --git a/src/templates/product.html.twig b/src/templates/product.html.twig
index 8634ec6..c56c4ea 100644
--- a/src/templates/product.html.twig
+++ b/src/templates/product.html.twig
@@ -3,6 +3,7 @@
{% block content %}