



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




This is the Exam Reference Booklet for the following Problems. You will not get any credit for written work in this booklet.
● Overview ● Project Directory and **** File Details ● Textbook API Documentation
Problem 2/3 Overview With textbook prices on the rise, the team that brought you Tricky Typing has begun work on their next big project: a full-stack website designed to help you find the cheapest available textbooks for your courses. In Problem 2, you will write the server-side app.js in Node/Express to implement the API following a provided specification. This API will then be used in Problem 3 (client-side books.js) to power the textbook search page (books.html). For both problems, you may assume the other is implemented correctly, and may choose to implement them in either order. On the rest of this page and the following page, we provide the Project Directory Structure as well as the reference API documentation. You will then find instructions for Problems 2/3.
For both problems, you should assume the following directory structure, where the front-end views are served from public/ similar to the other full-stack projects you’ve worked on in Modules 4/5. Each course has exactly one. txt file in the data directory, named in the format .txt with the first line being the full name of the required textbook and all following lines having the format seller:price to pair each seller known offering that textbook with their offered price (not assumed to be in any particular order). In this version of our API, we assume all courses in the data directly have only one textbook required. Directory structure book-finder/ └─ app.js data/ └─ CSE142.txt CSE154.txt HCDE308.txt PSYCH200.txt ... public/ └─ books.html books.js styles.css ** File Content Format** bookname seller1:price … sellerN:priceN Example CSE154.txt contents A Dog's Guide to Web Programming University Book Store:199. PetCo:200. Example HCDE308.txt contents Design of Everyday Things amazon:10. Example PSYCH200.txt contents Psychology of Dogs PetCo:19. Real Penny Dealz:0.
2. (Node.js) Books on a Budget You will implement the two endpoints as Part A and Part B, completing the rest of the app.js provided in the Answer Booklet. Finish app.js as specified in the Problem 2 section of the Exam 2 Answer Book. 3. (Client-side JS with AJAX) What’s an API without an interface? In this Problem, you will implement the client-side books.js to fetch from the textbooks API from Problem 2. Provided Screenshots: Figure 1: When page is loaded, after course buttons are populated on the page (retrieved from /courses endpoint ) Figure 2: After clicking the CSE154 button and populating the book info area. Initial Page Behavior When the page loads, you should make a GET request to the /courses endpoint. Recall that this endpoint will return a list of all available courses as newline-separated text. Use this response create and append a button element for each course to #courses with textContent being the course name. Viewing the Cheapest Textbook for a Course When a course button is clicked, a fetch call should be made to /books/:course , with the respective course name passed as the :course path parameter. Recall that this endpoint will return the cheapest book as a JSON object, shown below. Use this information to populate #book-name , #seller , and #price. The .hidden class should be removed from #book-info on success. Example response from /books/CSE154: { “name”: “A Dog’s Guide to Web Development”, “seller”: “University Bookstore”, “price”: 199. }
If an error is thrown during any fetch request to the API, #book-info and #courses should be hidden and #error-info should be made visible. Remember that you may assume checkStatus is provided with the rest of the id, qs, qsa, and gen helper functions. These are included in the cheatsheet for reference if needed. Provided books.html:
Book Finder
An error has occurred. Please refresh the page.
Available at for $
Select a course:
4. (SQL) Who needs .txt-books anyways? With the growth of their project, the Textbook Search team has decided to convert their .txt files into a MySQL database called booksdb. With this transition the team has expanded the capabilities of their service, enabling users to find cheap textbooks like never before. With this improved SQL-powered service, we can expand the scope of our textbook search - this table breakdown is similar to the directory and file structure you used in Problems 2/3, but now supports courses with multiple required books. The new textbook database consists of three tables (not all data shown): books The books table contains information for all textbooks on the service, including the name and author. The id column is a primary key. offers The offers table associates textbooks with their sellers, as well as the price offered by that seller. The offer_id column is a primary key, and the book_id column references the books table PRIMARY KEY. requirements The requirements table associates course names with their required textbooks. Remember that unlike the constraint in our .txt files in Problems 2/3, our table now allows each course to have multiple book_id s (e.g. CSE154 has 4 books in the requirements table). The book_id column references the books table PRIMARY KEY.