Skip to content
Snippets Groups Projects

Add Api for create review

Merged Muh Habibi Haidir requested to merge habibi_book into master
Compare and
4 files
+ 67
4
Preferences
Compare changes
Files
4
@@ -45,6 +45,21 @@
return $books;
}
function updateRating($book_id, $rating, $banyak_review) {
$books = $this->getBookById($book_id);
$now_rating = $books[0]->rating;
$new_rating = ((float)($now_rating * $banyak_review + $rating) / (float)($banyak_review + 1));
$book = null;
$sql = "UPDATE book SET rating = ? where book_id = ?";
$stmt = $this->conn->prepare($sql);
if ($stmt->execute([$new_rating, $book_id])) {
$book = new Book($book_id, null, null, null, $new_rating);
}
return $book;
}
}
?>
\ No newline at end of file