Deployed Application: https://bookend.herokuapp.com/
GitHub Repository: https://github.com/coderbennett/bookend
Bookend is a full stack application that allows readers to create an account and join a community of others in finding new books to read, viewing public book clubs, or even creating their own clubs and inviting their friends and family.
This code example shows an html route used for displaying information on a single book.
router.get("/book/:id", withAuth, async (req, res) => {
const bookData = await Book.findByPk(req.params.id, {
include: [
{
model: Review,
include: [{ model: Comment, include: Reader }, { model: Reader }],
},
],
});
if (!bookData) {
return res.status(404).json({ message: "No book found with this id." });
}
const book = bookData.get({ plain: true });
const bookFavoriteCount = await ReaderBook.count({
where: {
book_id: req.params.id,
},
});
const bookFavoriteByReaderData = await ReaderBook.findOne({
where: {
reader_id: req.session.user_id,
book_id: req.params.id,
},
});
console.log(book.reviews);
const isFavorite = bookFavoriteByReaderData ? true : false;
res.render("book", {
book: book,
bookFavoriteCount: bookFavoriteCount,
isFavorite: isFavorite,
logged_in: req.session.LoggedIn,
});
});
This code example shows an api route used to let a reader post a review for a book.
router.post("/", withAuth, async (req, res) => {
try {
const reviewData = await Review.create({
title: req.body.title,
body: req.body.body,
reader_id: req.session.user_id,
book_id: req.body.id,
});
res.status(200).json(reviewData);
} catch (err) {
res.status(400).json(err);
}
});
This code example is a function that was written and used in many different areas of the code base to determine logged in status and provide certain permissions based on the result.
const withAuth = (req, res, next) => {
if (!req.session.LoggedIn) {
res.redirect("/");
} else {
next();
}
};
module.exports = withAuth;
If there are any questions about this project, please reach out to any of the contributors via their GitHub profiles.
MIT License
Copyright (c) 2022 Joey Bennet, John Netzel, Andrew Mason
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.