Skip to content
Snippets Groups Projects
Commit 2bdb1c82 authored by Habibi's avatar Habibi
Browse files

Add search book feature

parent ad1899bb
Branches
1 merge request!1Habibi book
...@@ -25,6 +25,26 @@ ...@@ -25,6 +25,26 @@
} }
return $books; return $books;
} }
function getBookByTitle($title) {
$books = [];
$sql = 'SELECT * FROM book WHERE title LIKE \'%?%\'';
$stmt = $this->conn->prepare($sql);
$stmt->execute([$title]);
while($row = $stmt->fetch()) {
$book_id = (int) $row["book_id"];
$title = $row["title"];
$author = $row["author"];
$description = $row["description"];
$rating = $row["rating"];
$book = new Book($book_id, $title, $author, $description, $rating);
array_push($books, $book);
}
return $books;
}
} }
?> ?>
\ No newline at end of file
...@@ -18,6 +18,21 @@ ...@@ -18,6 +18,21 @@
writeResponse(500, 'Failed get book detail'); writeResponse(500, 'Failed get book detail');
} }
} }
function searchBook(Request $request) {
$title = (int)$request->params["title"];
if ($title) {
writeResponse(200, "Mantuls");
} else {
writeResponse(500, "Goblok");
}
// $books = $this->bookDb->getBookByTitle($title);
// if ($books) {
// writeResponse(200, "Success get book by title like " + $title, $books);
// } else {
// writeResponse(500, "Failed get book detail");
// }
}
} }
?> ?>
\ No newline at end of file
<?php <?php
function addBookRoutes($router, $bookUsecase){ function addBookRoutes($router, $bookUsecase){
$router->add("/book?title=xxx;", "GET", array($bookUsecase, 'searchBook'));
$router->add("/book/:book_id/", "GET", array($bookUsecase, 'getBookDetail')); $router->add("/book/:book_id/", "GET", array($bookUsecase, 'getBookDetail'));
// $router->add("/", "GET", $homepage, $middlewareExample); // $router->add("/", "GET", $homepage, $middlewareExample);
// $router->add("/book/:book_id/user/:user_id/", "POST", $postCallbackExample, $middlewareExample); // $router->add("/book/:book_id/user/:user_id/", "POST", $postCallbackExample, $middlewareExample);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment