Skip to content

EunsooJung/Shopping-Cart

Repository files navigation

Shopping Cart (Project II)

Create a Shopping Cart web applicaion with UI template engine, Node.js, Sequelize, ORM, sqlite3 schema and handle routes with Express, applying MVC Pattern then deploy to heroku.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

# Install packages
npm i body-parser express express-paginate express-ssion forms morgan nunjuncks sequelize sequelize-cli sqlite3 uuid

# Run
node server.js or npm start (using nodemon)

Preview

Shopping Cart

Usage

Basic Usage

To get Shopping Cart, after downloading, you need to make sure Git Bash terminal open and looking at the correct folder. When you are within the correct location, you may type the following commands to ask her for information:

  • node server.js

Guidelines:

  • Proceeds as follows:

To use this applicaion, Clone the applicaion to your local git repository or directory:

To start:

  • You have to install npm packages depend on my package.json file: "npm install"
  • Open your terminal then "node app.js"

Code Snippet

  • Project structure

    [Shopping Cart-Project-Structure]

  • Database ERD

    [Shopping Cart-ERD]

  • Source Code Check point

  1. folder "models": It provides sequelize Schema model
'use strict';
module.exports = (sequelize, DataTypes) => {
  const Customer = sequelize.define(
    'Customer',
    {
      personId: DataTypes.INTEGER,
      isDeleted: DataTypes.BOOLEAN
    },
    {}
  );
  Customer.associate = function(models) {
    Customer.belongsTo(models.Person);
    Customer.belongsToMany(models.Address, { through: models.CustomerAddress });
  };
  return Customer;
};
  1. folder "public": It provides images and css files

  2. Controller layer: Server-Side routes

  • Create all of this Shopping Cart web application's routes (maps) using a exppress router.
/* Get all products */
var getPagedProducts = function(req, res) {
  if (req.method === 'POST') {
    cartService.addToCart(req);
    res.redirect(req.body.originalUrl);
  } else {
    fetchPaginatedProducts(req, res);
  }
};
  1. app.js:

    • Setup Shopping Cart web applicaion's environments (npm package dependencies)
    • Import Register the Routers to access.
  2. forms: It provides forms to checkout page.

  3. migrations: It provides Database schema migration.

  4. views: View layer to represent user interface.

  5. services: It provides services to controller.

// View Engine SetUp
nunjucks.configure(
  [
    'views',
    'views/cataloguedm',
    'views/cataloguedm/partials',
    'views/cartdm',
    'views/cartdm/partials',
    'views/checkoutdm'
  ],
  {
    autoescape: true,
    express: app
  }
);
...
// Make the cart parameters available to the templates
app.use(contextProcessor.localContext);

routerRegister(app);

Built With

  • Javascript
  • Node.js
  • MySQL
  • MVC Patterns
  • cookieParser
    • Parse Cookie header and populate req.cookies with an object keyed by the cookie names. Optionally you may enable signed cookie support by passing a secret string, which assigns req.secret so it may be used by other middleware.
  • body-parser
    • Node.js body parsing middleware.
    • Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
  • nunjucks
    • Nunjucks is a full featured templating engine for javascript. It is heavily inspired by jinja2.
  • express-paginate
    • Node.js pagination middleware and view helpers.
  • sqlite3
    • SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine.
  • forms
    • This module is an attempt to provide the same sort of helpers for node.js.

Authors

  • Michael(Eunsoo)Jung

License

This project is licensed under the MIT License

About

Create a Shopping Cart web applicaion with UI template engine, Node.js, Sequelize, ORM, sqlite3 schema and handle routes with Express, applying MVC Pattern then deploy to heroku.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published