Giter Club home page Giter Club logo

e-commerce-backend's Introduction

E-Commerce Backend

This is the backend application for an E-Commerce website. It provides RESTful API endpoints for managing products, categories, and tags. The application is built using Node.js, Express.js, and Sequelize as the ORM for MySQL.

Table of Contents

Mock up

13-orm-homework-demo-01 13-orm-homework-demo-02

Installation

Clone the repository:

   git clone https://github.com/your-username/e-commerce-backend.git
  1. Navigate to the project directory:

    Copy code
    cd e-commerce-backend
    
  2. Install dependencies:

    Copy code
    npm install
    

Usage

  1. Set up the database configuration:
  • Create a .env file in the root directory.
  • Add your MySQL database credentials:
    env
    Copy code
    DB_NAME=your_database_name
    DB_USER=your_database_user
    DB_PASSWORD=your_database_password
    
    
  1. Start the application:

    Copy code
    npm start
    The server will be running at http://localhost:3001.
    
    

Database Setup

  1. Create a MySQL database.

  2. Update the .env file with your database details.

  3. Run the Sequelize migrations to create tables:

    Copy code
    npm run migrate
    Seed the database with sample data:
    
    ```bash 
    Copy code
    npm run seed
    
    

API Endpoints

Categories:

  • GET /api/categories
  • GET /api/categories/:id
  • POST /api/categories
  • PUT /api/categories/:id
  • DELETE /api/categories/:id

Products:

  • GET /api/products
  • GET /api/products/:id
  • POST /api/products
  • PUT /api/products/:id
  • DELETE /api/products/:id

Tags:

  • GET /api/tags
  • GET /api/tags/:id
  • POST /api/tags
  • PUT /api/tags/:id
  • DELETE /api/tags/:id

Models

Category:

  • id (INTEGER, PRIMARY KEY)
  • category_name (STRING)

Product:

  • id (INTEGER, PRIMARY KEY)
  • product_name (STRING)
  • price (DECIMAL)
  • stock (INTEGER)
  • category_id (INTEGER, FOREIGN KEY)

Tag:

  • id (INTEGER, PRIMARY KEY)
  • tag_name (STRING)

ProductTag:

  • id (INTEGER, PRIMARY KEY)
  • product_id (INTEGER, FOREIGN KEY)
  • tag_id (INTEGER, FOREIGN KEY)

Contributing

Contributions are welcome! Please follow the Contribution Guidelines.

License

This project is licensed under the MIT License.

e-commerce-backend's People

Contributors

jay1194 avatar

Watchers

 avatar

e-commerce-backend's Issues

Finish Database

Getting Started

  1. Use the MySQL2 and Sequelize packages to connect the Express.js API to MySQL database and the dotenv package to use environment variables to store sensitive data, like my MySQL username, password, and database name.

  2. Use the Schema.sql file in the db folder to create the database using MySQL shell commands. Use environment variables to store sensitive data, like my MySQL username, password, and database name.

Seed the Database

  • After creating the models and routes, run npm run seed to seed data to the database so that you can test your routes.

Sync Sequelize to the Database on Server Start

  • Create the code needed in server.js to sync the Sequelize models to the MYSQL database on server start.

Create Associations

Execute association methods on Sequelize models to create the relationships between them:

  1. Product belongs to Category, as a category can have multiple products but a product can only belong to one category.

  2. Category has many Product models.

  3. Product belongs to many Tag models. Using the ProductTag through model, allow products to have multiple tags and tags to have many products.

  4. Tag belongs to many Product models.

Create Database Models

Database should contain the four models including requirements listed for each model:

1. Category

  • id

    • Integer
    • Doesn't allow null values
    • Set as primary key
    • Uses auto-increment
  • category_name

    • String
    • Doesn't allow null values

2. Product

  • id

    • Integer
    • Doesn't allow null values
    • Set as primary key
    • Uses auto-increment
  • product_name

    • String
    • Doesn't allow null values
  • price

    • Decimal
    • Doesn't allow null values
    • Validates the value is a decimal
  • stock

    • Integer
    • Doesn't allow null values
    • Set a default value of 10
    • Validates the value is numeric
  • category_id

    • Integer
    • References the category model's id

3. tag

  • id

    • Integer
    • Doesn't allow null values
    • Set as primary key
    • Uses auto-increment
  • tag_name

    • String

4. ProductTag

  • id

    • Integer
    • Doesn't allow null values
    • Set as primary key
    • Uses auto-increment
  • product_id

    • Integer
    • References the product model's id
  • tag_id

    • Integer
    • References the tag model's id

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.