Name: Rupeng Liu
Date: May 3 2018
Project Topic: Online Book Store
Data point fields:
Schema: Book
-Field 1
: Title Type: Text
-Field 2
: Year Type: Number
-Field 3
: Author Type: Text
-Field 4
: Words Type: Number
-Field 5
: Purchases Type: [purchaseschema]
Schema:
var bookSchema = new mongoose.Schema({
title: {
type: String,
required: true
},
year: {
type: Number,
min: 0,
max: 2018,
required: true
},
author: {
type: String,
required: true
},
words: {
type: Number,
},
purchases: [purchaseSchema]
});
Schema: Purchase
-Field 1
: Price Type: Number
-Field 2
: Store Type: Number
-Field 3
: Purchasedate Type: Date
-Field 4
: Comment Type: Text
-Field 5
: Publisher Type: Text
Schema:
var purchaseSchema = new mongoose.Schema({
price: {
type: Number,
required: true
},
comment: {
type: String,
},
publisher: {
type: String,
},
purchasedate: {
type: String,
},
store: {
type: String,
required: true
}
});
HTML form route: /addBook
HTML form route: (purchase) /book/:id/purchase
POST endpoint route: /api/addBook
Example Node.js POST request to endpoint:
var request = require("request");
var options = {
method: 'POST',
url: 'http://localhost:3000/api/addBook',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
form: {
title: Road,
year: 2014,
author: Mike,
words: 2428347,
purchases: []
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
GET endpoint route: /api/getbooks
Search Field: Title
Endpoint route: /getbook/:title
Navigation Filters <br/ >
- Thick Book ->
/thickbook
- Allen's Book ->
/Allen
- New Book ->
/newbook
- Old Book ->
/oldbook
- Popular Book ->
/popbook