diff --git a/app/controller/book/BookDb.php b/app/controller/book/BookDb.php index 7d38d9716c83d838db9fe60821f98915fee864d1..4f3fa933fc7a726e55003f6908d392bda10ef31e 100644 --- a/app/controller/book/BookDb.php +++ b/app/controller/book/BookDb.php @@ -74,12 +74,15 @@ $content = $row["content"]; $rating = (float) $row["rating"]; - $sqlUsername = 'SELECT username FROM user WHERE user_id = ?'; - $stmtUsername = $this->conn->prepare($sqlUsername); - $stmtUsername->execute([$user_id]); - $username = $stmtUsername->fetch()['username']; + $sqlUser = 'SELECT username, img_path FROM user WHERE user_id = ?'; + $stmtUser = $this->conn->prepare($sqlUser); + $stmtUser->execute([$user_id]); + $rowUser = $stmtUser->fetch(); + $username = $rowUser['username']; + $imgPath = $rowUser['img_path']; + - $review = new Review($review_id, $user_id, $book_id, $content, $rating, $username); + $review = new Review($review_id, $user_id, $book_id, $content, $rating, null, $username, $imgPath); array_push($reviews, $review); } return $reviews; diff --git a/app/controller/book/BookUsecase.php b/app/controller/book/BookUsecase.php index b45f38777df5dee094be1db27fd2cc01ede487af..c4e5c14406df90431745d560d952b27e1ba8461c 100644 --- a/app/controller/book/BookUsecase.php +++ b/app/controller/book/BookUsecase.php @@ -17,6 +17,7 @@ "books" => $books, "reviews" => $reviews, ]; + render('bookDetail.php', $data); } else { writeResponse(500, 'Failed get book detail'); diff --git a/app/controller/book/routes.php b/app/controller/book/routes.php index 8071f9eee5bf46bbd7c26b42b6d8e03e8cf63509..952787a3870855452456a02025801dea7b69a851 100644 --- a/app/controller/book/routes.php +++ b/app/controller/book/routes.php @@ -2,7 +2,7 @@ function addBookRoutes($router, $bookUsecase){ $router->add("/results/", "GET", array($bookUsecase, 'searchBook'), new AuthMiddleware()); - $router->add("/book/:book_id/", "GET", array($bookUsecase, 'getBookDetail')); + $router->add("/book/:book_id/", "GET", array($bookUsecase, 'getBookDetail'), new AuthMiddleware()); // $router->add("/", "GET", $homepage, $middlewareExample); // $router->add("/book/:book_id/user/:user_id/", "POST", $postCallbackExample, $middlewareExample); // $router->add("/book/:book_id/", "POST", $postCallbackExample, $middlewareExample); diff --git a/app/controller/order/OrderDb.php b/app/controller/order/OrderDb.php index b062efca4b648f34b95091d2aeae21f859eca2da..c0193421ecbf79c5532d9a4a3f377eb1154398ea 100644 --- a/app/controller/order/OrderDb.php +++ b/app/controller/order/OrderDb.php @@ -27,7 +27,7 @@ function getOrder($id) { $orders = []; - $sql = 'SELECT * FROM order_book WHERE user_id = ?'; + $sql = 'SELECT * FROM order_book WHERE user_id = ? ORDER BY order_book_id DESC'; $stmt = $this->conn->prepare($sql); $stmt->execute([$id]); @@ -38,9 +38,9 @@ $item_count = $row["item_count"]; $date = $row["order_date"]; - $sqlBook = 'SELECT * FROM review WHERE user_id = ? AND book_id = ?'; + $sqlBook = 'SELECT * FROM review WHERE user_id = ? AND book_id = ? AND order_id = ?'; $stmtBook = $this->conn->prepare($sqlBook); - $stmtBook->execute([$user_id, $book_id]); + $stmtBook->execute([$user_id, $book_id, $order_id]); if ($stmtBook->fetch()) { $has_review = true; } else { diff --git a/app/controller/order/routes.php b/app/controller/order/routes.php index 373626b4d5aa9d37fecd45a382517f6c76f6b9cb..cf14c95546f0e584e0c786373f46c0030e1c2c6f 100644 --- a/app/controller/order/routes.php +++ b/app/controller/order/routes.php @@ -1,8 +1,8 @@ <?php function addOrderRoutes($router, $orderUsecase){ - $router->add("/history/", "GET", array($orderUsecase,'getOrder')); - $router->add("/api/order/", "POST", array($orderUsecase, 'addOrder')); + $router->add("/history/", "GET", array($orderUsecase,'getOrder'), new AuthMiddleware()); + $router->add("/api/order/", "POST", array($orderUsecase, 'addOrder'), new AuthMiddleware()); // $router->add("/", "GET", $homepage, $middlewareExample); // $router->add("/book/:book_id/user/:user_id/", "POST", $postCallbackExample, $middlewareExample); // $router->add("/book/:book_id/", "POST", $postCallbackExample, $middlewareExample); diff --git a/app/controller/review/Review.php b/app/controller/review/Review.php index 3244b6083a130c2b8e2178d90af7d6a1985b8e0f..5eb9916901b557d785693678805de0df48387bd8 100644 --- a/app/controller/review/Review.php +++ b/app/controller/review/Review.php @@ -6,14 +6,18 @@ public $content; public $rating; public $username; + public $order_id; + public $user_img; - function __construct($review_id, $user_id, $book_id, $content, $rating, $username = null) { + function __construct($review_id, $user_id, $book_id, $content, $rating, $order_id, $username = null, $user_img = null) { $this->review_id = $review_id; $this->user_id = $user_id; $this->book_id = $book_id; $this->content = $content; $this->rating = $rating; + $this->order_id = $order_id; $this->username = $username; + $this->user_img = $user_img; } } ?> \ No newline at end of file diff --git a/app/controller/review/ReviewDb.php b/app/controller/review/ReviewDb.php index ced5131beba12684bdaf1ecf7d3eb16532e4c4b5..880d3891d57e4cec4e970bcefa38f03853d93f47 100644 --- a/app/controller/review/ReviewDb.php +++ b/app/controller/review/ReviewDb.php @@ -42,15 +42,15 @@ function createReview($review) { $reviewRes = null; - $sql = 'INSERT INTO review(user_id, book_id, content, rating) VALUES(?,?,?,?)'; + $sql = 'INSERT INTO review(user_id, book_id, content, rating, order_id) VALUES(?,?,?,?, ?)'; $stmt = $this->conn->prepare($sql); - if ($stmt->execute([$review->user_id, $review->book_id, $review->content, $review->rating])) { + if ($stmt->execute([$review->user_id, $review->book_id, $review->content, $review->rating, $review->order_id])) { $review_id = 0; $last_insert_id = $this->conn->query("SELECT LAST_INSERT_ID()"); foreach($last_insert_id as $row) { $review_id = $row["LAST_INSERT_ID()"]; }; - $reviewRes = new Review($review_id, $review->user_id, $review->book_id, $review->content, $review->rating); + $reviewRes = new Review($review_id, $review->user_id, $review->book_id, $review->content, $review->rating, $review->order_id); $banyak_review = $this->getReviewsCount($review->book_id); $bookDb = new BookDb($this->conn); diff --git a/app/controller/review/ReviewUsecase.php b/app/controller/review/ReviewUsecase.php index a0d20082b6449c935d71d470af029f9762795b70..6ffa4e1e733529fae18899f482a8865c6ec8f58f 100644 --- a/app/controller/review/ReviewUsecase.php +++ b/app/controller/review/ReviewUsecase.php @@ -19,8 +19,9 @@ $book_id = (int)$request->payload["book_id"]; $content = $request->payload["content"]; $rating = (int)$request->payload["rating"]; + $order_id = (int)$request->payload["order_id"]; - $review = new Review(null, $user_id, $book_id, $content, $rating); + $review = new Review(null, $user_id, $book_id, $content, $rating, $order_id); $review = $this->reviewDb->createReview($review); if ($review) { header('Location: /history/'); diff --git a/app/controller/review/routes.php b/app/controller/review/routes.php index f4ec68895066be172a75e9d8d1207c3936ace998..647182607090e8e52dec3446ffd10d93d6edabd7 100644 --- a/app/controller/review/routes.php +++ b/app/controller/review/routes.php @@ -1,8 +1,8 @@ <?php function addReviewRoutes($router, $reviewUsecase){ - $router->add("/api/review/reviews/:book_id/", "GET", array($reviewUsecase,'getReviews')); - $router->add("/review/:book_id/", "GET", array($reviewUsecase, "getReviewBookDetail")); - $router->add("/api/review/", "POST", array($reviewUsecase, 'addReview')); + $router->add("/api/review/reviews/:book_id/", "GET", array($reviewUsecase,'getReviews'), new AuthMiddleware()); + $router->add("/review/:book_id/", "GET", array($reviewUsecase, "getReviewBookDetail"), new AuthMiddleware()); + $router->add("/api/review/", "POST", array($reviewUsecase, 'addReview'), new AuthMiddleware()); return $router; } diff --git a/app/controller/user/UserUsecase.php b/app/controller/user/UserUsecase.php index 334cd56727243f0ff8ee2b04230b0c8c90ee3ec9..0421f0ab078dfb817a3d376c4dd82c6d7ff8ccc0 100644 --- a/app/controller/user/UserUsecase.php +++ b/app/controller/user/UserUsecase.php @@ -40,7 +40,6 @@ ); $jwt = generateJWT($payload); setcookie("Authorization", $jwt["token"], time()+APP_CONFIG["cookie_duration"],"/"); - var_dump($_COOKIE["Authorization"]); header('Location: /browse/'); } else { writeResponse(500, "Failed register user"); } @@ -60,7 +59,7 @@ $id = getJwtData($_COOKIE["Authorization"])->user_id; $user = $this->userDb->getUserById($id); if ($user){ - + $imageFile = $_FILES["profile_picture"]; $uploadImage = $this->userDb->uploadImage($imageFile); $user->username = array_key_exists("username",$_POST) ? $_POST["username"] : $user->username; @@ -104,7 +103,6 @@ ); $jwt = generateJWT($payload); setcookie("Authorization", $jwt["token"], time()+APP_CONFIG["jwt_duration"],"/"); - var_dump($_COOKIE["Authorization"]); header('Location: /browse/'); } else { render('login.php',array("isError"=>true)); diff --git a/app/view/bookDetail.php b/app/view/bookDetail.php index 0e6eb7faf84300f452474c5fd8db96e14141b8a8..3864e1ee47c50b2448d015ab41bef11ee56bb84d 100644 --- a/app/view/bookDetail.php +++ b/app/view/bookDetail.php @@ -100,7 +100,7 @@ echo(" <div class=\"review-container\"> <div class=\"review\"> - <img src=\"/static/img/tayoblue.jpg\" class=\"img-review-user\"> + <img src=\"$review->user_img\" class=\"img-review-user\"> <div class=\"username\">@$review->username</div> <div class=\"review-desc\"> $review->content diff --git a/app/view/browse.php b/app/view/browse.php index af17d19778337af5f830729253a33f59622b945e..b297feceb9b81de8a684206e315070fffda0d35c 100644 --- a/app/view/browse.php +++ b/app/view/browse.php @@ -1,3 +1,4 @@ +<title>Browse</title> <?php render('header.php'); include __STATIC__.'/html/browse.html'; diff --git a/app/view/history.php b/app/view/history.php index 29c6a67072016adac0ded4c51e9f35a120ae9634..5fb25ccb9bfcf102041ecc99764639130c10589c 100644 --- a/app/view/history.php +++ b/app/view/history.php @@ -1,7 +1,7 @@ <?php render('header.php'); ?> - +<title>History</title> <link rel="stylesheet" href="/static/css/base.css"> <link rel="stylesheet" href="/static/css/history.css"> @@ -20,7 +20,7 @@ $status = 'Belum direview'; $button = " <div class=\"submit-review\"> - <a href=\"/review/$book_id/\"> + <a href=\"/review/$book_id/?order_id=$order->order_id\"> <button class=\"submit-button\">Review</button> </a> </div> diff --git a/app/view/homepage.php b/app/view/homepage.php deleted file mode 100644 index 6eb1b261df2376755d8602a430f0bf56dca18019..0000000000000000000000000000000000000000 --- a/app/view/homepage.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - $homepage = function() { - include __VIEW__.'/static/html/header.html'; - include __VIEW__.'/static/html/browse.html'; - if ($_COOKIE["user"]){ - echo $_COOKIE["user"]; - setcookie("user","", time()-3600); - } else { - echo "gada cookie"; - setcookie("user",1); - } - } -?> \ No newline at end of file diff --git a/app/view/login.php b/app/view/login.php index 4057fd67ea84a6bb616ab00e0b436a0d822beb3d..dd92a37f636b2712293e0882ffc67daccc969d86 100644 --- a/app/view/login.php +++ b/app/view/login.php @@ -1,16 +1,18 @@ <link rel="stylesheet" href="/static/css/login.css"> <link rel="stylesheet" href="/static/css/base.css"> +<title>Login</title> + <div class="container"> - <form class="form" action="/login/" method="POST"> + <form class="form" action="/login/" method="POST" onSubmit="return validateForm()"> <h1 class="form-title">LOGIN</h1> <div class="row"> <label for="username_form" class="form-label">Username</label> - <input class="form-input" type="text" name="username" id="username_form"> + <input class="form-input" type="text" name="username" id="username_form" required> </div> <div class="row"> <label for="password_form" class="form-label">Password</label> - <input class="form-input" type="password" name="password" id="password_form"> + <input class="form-input" type="password" name="password" id="password_form" required> </div> <a class="register-link" href="/register/">Don't have an account?</a> <br> @@ -20,6 +22,7 @@ </form> </div> +<script src="/static/js/login.js"></script> <?php if ($isError){ diff --git a/app/view/register.php b/app/view/register.php index bde26f52be306c991af8055bfe0adeeb60808954..af646255f894106ead3110cb34e2e2b9cbb11bae 100644 --- a/app/view/register.php +++ b/app/view/register.php @@ -1,3 +1,4 @@ +<title>Register</title> <?php include __STATIC__.'/html/register.html'; include __STATIC__.'/html/footer.html'; diff --git a/app/view/result.php b/app/view/result.php deleted file mode 100644 index 9fae434fbaf4985cca6024790f7187cfb53b15b2..0000000000000000000000000000000000000000 --- a/app/view/result.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - include __STATIC__.'/html/header.html'; - include __STATIC__.'/html/search_result.html'; - // Include content here; - include __STATIC__.'/html/footer.html'; - // echo $_COOKIE["user"]; -?> \ No newline at end of file diff --git a/app/view/review.php b/app/view/review.php index 117a427493a2ae14654080d35fae2a6061b08388..fdafaa8f1771cb982ce0779a306c86434d8d9a77 100644 --- a/app/view/review.php +++ b/app/view/review.php @@ -1,8 +1,8 @@ <?php - include __STATIC__.'/html/header.html'; + render('header.php'); // echo $_COOKIE["user"]; ?> - +<title>Review</title> <link rel="stylesheet" href="/static/css/base.css"> <link rel="stylesheet" href="/static/css/review.css"> <div class="review-container"> @@ -64,6 +64,7 @@ name="content" rows="10" class="review-comment" + required ></textarea> <input type="hidden" @@ -92,6 +93,17 @@ /> ") ?> + <?php + $order_id = (int)$_GET["order_id"]; + + echo(" + <input + type=\"hidden\" + name=\"order_id\" + value=$order_id + /> + ") + ?> <div class="justify-content-between"> <div class='review-back'> <a href="/history/"> diff --git a/app/view/searchResult.php b/app/view/searchResult.php index 1d5ebae8a14e547277a8de2d09ad1c5c676f4240..08ab91288788f3f0adc417ff21ab673bfb4f8423 100644 --- a/app/view/searchResult.php +++ b/app/view/searchResult.php @@ -1,7 +1,7 @@ <?php render('header.php'); ?> - +<title>Search Result</title> <link rel="stylesheet" href="/static/css/base.css"> <link rel="stylesheet" href="/static/css/search_result.css"> <div class="content search-result"> diff --git a/public/static/css/register.css b/public/static/css/register.css index 78faa9669426cb84c5c5059ffa7f2a0b86b34368..8e65ed7fa17d61dfe9132b6a65e3da2af58705b9 100644 --- a/public/static/css/register.css +++ b/public/static/css/register.css @@ -4,7 +4,7 @@ body{ .container { margin: 0 auto; - width:30%; + width:35%; padding: 50px 15px 50px 15px; margin-top: 100px; background-color: #00AFEA; diff --git a/public/static/html/browse.html b/public/static/html/browse.html index dd19e83eb85b143f1a49a1fe72c731180c25cb89..5e6b9ec36c2d0b6da52add90ed8129069c6ce815 100644 --- a/public/static/html/browse.html +++ b/public/static/html/browse.html @@ -6,12 +6,13 @@ Search Book </h1> </div> - <form action="/results/" method="GET"> + <form action="/results/" method="GET" onsubmit="return validateForm()"> <input type="text" class="search-book" name="title" placeholder="Input search terms..." + required /> <div class="justify-content-end"> <button class="button-search-book" id="button-search-book"><span>Search</span></button> diff --git a/public/static/img/Habibi.jpg b/public/static/img/Habibi.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c1e47eab4ffd9d6a257a33111d76915d39c905a6 Binary files /dev/null and b/public/static/img/Habibi.jpg differ diff --git a/public/static/js/browse.js b/public/static/js/browse.js new file mode 100644 index 0000000000000000000000000000000000000000..d861c1e926493353dd3a17a0807d33af71b416cb --- /dev/null +++ b/public/static/js/browse.js @@ -0,0 +1,10 @@ +function validateForm() { + let searchBook = document.getElementById('search_book').value; + + if (!searchBook) { + return false; + } + + return false; + return true; +} \ No newline at end of file diff --git a/public/static/js/register.js b/public/static/js/register.js index f01d5a3108feeb741a725b0b55d84559be58a9ce..164a1a4ff3390446ab7e54d02db56a6efb25aa49 100644 --- a/public/static/js/register.js +++ b/public/static/js/register.js @@ -23,10 +23,11 @@ function enableValidateUsername(){ const usernameValue = username.value; const validateUsernameURL = '/api/user/validateUsername/?username='+username.value; doAjax(validateUsernameURL, "GET", null, function(response){ + console.log(response); if ((usernameValue.length<=20 && usernameValue.length>0) && !response.data){ isUsernameValid = true; username.style.border = ""; - usernameCheck.style.display = "block"; + usernameCheck.style.display = "inline"; }else { isUsernameValid = false; username.style.border = errorStyle; @@ -42,11 +43,10 @@ function enableValidateEmail(){ const emailValue = email.value; const validateEmailURL = '/api/user/validateEmail/?email='+email.value; doAjax(validateEmailURL, "GET", null, function(response){ - console.log(response.data); if (emailValue.length>0 && !response.data && emailRegex.test(email.value) ){ isEmailValid = true; email.style.border = ""; - emailCheck.style.display = "block"; + emailCheck.style.display = "inline"; }else { isEmailValid = false; email.style.border = errorStyle;