Skip to content

RupengLiu/389spring2018

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 

Repository files navigation

Online Book Store

Name: Rupeng Liu
Date: May 3 2018
Project Topic: Online Book Store

1. Data Format and Storage

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
    }

});

2. Add New Data

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);
});

3. View Data

GET endpoint route: /api/getbooks

4. Search Data

Search Field: Title
Endpoint route: /getbook/:title

5. Navigation Pages

Navigation Filters <br/ >

  1. Thick Book -> /thickbook
  2. Allen's Book -> /Allen
  3. New Book -> /newbook
  4. Old Book -> /oldbook
  5. Popular Book -> /popbook

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published