-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tonicospinelli/06-front-controller
refactoring: create front controller
- Loading branch information
Showing
11 changed files
with
109 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
function productListAction() | ||
{ | ||
$products = findAllProducts(); | ||
include TEMPLATE_DIR . '/products/list.php'; | ||
} | ||
|
||
function productAddAction($post) | ||
{ | ||
$product = getProductFromPost($post['product']); | ||
|
||
if (addProduct($product)) { | ||
$successmsg = 'Product was saved successfully!'; | ||
} else { | ||
$errormsg = 'Product could not be added! :('; | ||
} | ||
productListAction(); | ||
} | ||
|
||
function productRemoveAction($id) | ||
{ | ||
if (!removeProduct($id)) { | ||
$errormsg = 'Product could not be removed! :('; | ||
} | ||
|
||
header('Location: /index.php/products'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
function wishlistListAction($email) | ||
{ | ||
$wishlist = findAllWishProducts($email); | ||
include TEMPLATE_DIR . '/wishlists/list.php'; | ||
} | ||
|
||
function wishlistAddAction($email, $post) | ||
{ | ||
$wishItem = getWishList($post['wish_item']); | ||
if (addWishItem($wishItem)) { | ||
$successmsg = 'Product was added at wish list successfully!'; | ||
} else { | ||
$errormsg = 'Product could not be added at wishlist! :('; | ||
} | ||
wishlistListAction($email); | ||
} | ||
|
||
function wishlistRemoveAction($email, $id) | ||
{ | ||
if (!removeWishItem($id)) { | ||
$errormsg = 'Product could not be removed from wishlist! :('; | ||
} | ||
header('Location: /wishlist?' . http_build_query(['email' => $_GET['email']])); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../config/app.php'; | ||
|
||
/** | ||
* @return PDO | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
// load and initialize any global libraries | ||
require_once __DIR__ . '/../config/app.php'; | ||
require_once LIBRARY_DIR . '/functions.php'; | ||
require_once LIBRARY_DIR . '/dbconn.php'; | ||
require_once LIBRARY_DIR . '/models/product.php'; | ||
require_once LIBRARY_DIR . '/controllers/product.php'; | ||
require_once LIBRARY_DIR . '/models/wishlist.php'; | ||
require_once LIBRARY_DIR . '/controllers/wishlist.php'; | ||
|
||
// route the request internally | ||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | ||
|
||
if ('/index.php/products' === $uri) { | ||
productListAction(); | ||
} elseif ('/index.php/products/add' === $uri && isset($_POST['product']) && isValidProduct($_POST['product'])) { | ||
productAddAction($_POST); | ||
} elseif ('/index.php/products/remove' === $uri && isset($_GET['remove'])) { | ||
productRemoveAction($_GET['remove']); | ||
} elseif ('/index.php/wishlist' === $uri && isset($_GET['email'])) { | ||
wishlistListAction($_GET['email']); | ||
} elseif ('/index.php/wishlist/add' === $uri && isset($_GET['email']) && isset($_POST['submit']) && isValidWishList($_POST['wish_item'])) { | ||
wishlistAddAction($_GET['email'], $_POST); | ||
} elseif ('/index.php/wishlist/remove' === $uri && isset($_GET['email']) && isset($_GET['remove'])) { | ||
wishlistRemoveAction($_GET['email'], $_GET['remove']); | ||
} else { | ||
header('HTTP/1.1 404 Not Found'); | ||
echo '<html><body><h1>Page Not Found</h1></body></html>'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters