Html / CSS
Overview: Using your knowledge of NodeJS and ExpressJS and the Web App Template provided, complete the Favourite Book List web app that you will share on GitHub and deploy to Heroku (or another cloud provider). Your web app already includes basic navigation controls, a Landing Page, a BookList page and a BookDetails page. Your task is to complete the code that is missing from the routing files and the Books List page so that a user can Add, Delete and Edit any Book item from the Database
Project Setup:
You will need to create a new Mongo Database on MongoDB Atlas. You will need to change the URI variable in the db config file (config/db.js) to point MongoDB Atlas.
You will need to add some example Book data in the database.
Instructions:
1. The BooksList page (views/books/index.ejs) already lists your favourite books. Your job is to fix the Add Button, and insert the appropriate code for the Edit and Delete Buttons (2 Marks: GUI, 13 Marks: Functionality):
a. Fix the Add Button on this page so that it links to the BookDetails page (views/books/details.ejs). Hint: insert the correct route in the href attribute. (3 Mark: Functionality).
b. Add an Edit Button to each row of the existing Table (the insertion point has been marked for you). Ensure that when the user clicks on the Edit button, they are linked to the BookDetails page and the _id of the book they wish to edit is passed to that page via the URL. Hint: the href attribute requires a reference to the _id of the book being edited (1 Mark: GUI, 6 Marks: Functionality).
c. Add a Delete Button to each row of the existing Table (the insertion point has been marked for you). Ensure that when the user clicks on the Delete button, that the _id of the book to be deleted is passed to the router. Hint: the href attribute requires both a link to the delete route and a reference to the _id of the book being edited (1 Mark: GUI, 4 Marks: Functionality).
2. The Books Routing File (routes/books.js) already has a route working to find all the books in the books collection and render your BooksList page. Your task for this section is to complete the logic for each of the other routes to render the book details page when the Add or Edit Buttons are clicked, process a request to Add or Edit a Book, and process a request to Delete a book (63 Marks: Functionality).:
a. Complete the get(‘/add’) router logic that renders the book details page (views/books/details.ejs). The form on the book details page will initially be blank. You must pass an appropriate value for the title property and blank value for the books property. (10 Marks: Functionality).
b. Complete the post(‘/add’) router logic that processes the insertion of a new book into the database. You need to instantiate an object of the book model (excluding the _id property) and pass this object to the create method of the book model to add a new book to the database. Hint: the values for the book object will come from the name attributes of each field of the book details page. Redirect the user back to the BookList page (‘/books’) when the insertion is completed. (10 Marks: Functionality).
c. Complete the get(‘/:id’) router logic that renders the book details page (views/books/details.ejs) and uses the id from the URL to select the book to document to be updated. Declare an id variable and set its value to the id property of the request object. Pass this id to the book model’s findById method to render the book details view. You must set an appropriate title property value and set the books property to the book that was returned from the database as you render the view. (15 Marks: Functionality).
d. Complete the post(‘/:id’) router logic that processes the update request of an existing book by using its id property. Declare an id variable and set its value to the id property of the request object. You need to instantiate an object of the book model (including the _id property) and pass this object to the update method of the book model to edit an existing book in the database. Hint: the values for the book object will come from the name attributes of each field of the book details page. Redirect the user back to the BookList page (‘/books’) when the update is completed. (20 Marks: Functionality).
e. Complete the get(‘/delete/:id’) router logic that processes the user’s delete request and removes an existing book from database by using its id property. Declare an id variable and set its value to the id property of the request object. Pass the id to the book model’s remove method. Redirect the user back to the BookList page (‘/books’) when the removal is completed. (8 Marks: Functionality).
3. Include Internal Documentation for your site (4 Marks: Internal Documentation):
a. Ensure you include a comment header for your JavaScript file that indicate: The File name, Author’s name and Web App name (1 Marks: Internal Documentation).
b. Ensure you include a section header for any JavaScript functions (1 Marks: Internal Documentation)
c. Ensure all your code uses contextual variable names that help make the files humanreadable (1 Marks: Internal Documentation).
d. Ensure you include inline comments that describe your GUI Design and Functionality. Note: avoid “over-commenting” (1 Marks: Internal Documentation)