Skip to content

RESTful API for dropshipping sales management. Developed in Node.js with MySQL and MSC architecture.

Notifications You must be signed in to change notification settings

garciaagui/store-manager

Repository files navigation

Project Store Manager 🛍️

🇧🇷 Clique aqui para acessar a versão em português.

Summary

  1. Description
  2. Technologies
  3. Features
  4. How to Run
  5. Endpoints
  6. About Trybe
  7. Contact

Description

21st project of the Trybe Web Development course.

This application is a RESTful API designed for managing dropshipping sales, allowing the creation, viewing, deletion, and updating (CRUD) of products and sales. It was developed in Node.js with MySQL database, following the MSC (Model-Service-Controller) architecture.

🎲 Here you can go deeper into the database structure.

Entity-Relationship Diagram

DER

ℹ️ Image created and provided by Trybe.


Entities format

The data below are fictitious and used only to exemplify the structure of the database tables.

  • A table called products, with the following structure:

    id name
    1 Martelo do Thor
  • A table called sales, with the following structure:

    id date
    1 2022-05-27 01:59:51
  • A table called sales_products, which establishes a N:N relationship between products and sales and has the following structure:

    sale_id product_id quantity
    1 1 5

Technologies

💻 Development

🧪 Testing

✨ Code alignment and quality


Features

  • Create, list, update, and delete products.
  • Create, list, update, and delete sales.

How to Run

To run the project, follow the steps below.

  1. Clone the repository;
git clone git@github.com:garciaagui/store-manager.git
  1. Navigate to the root of the project;
cd store-manager/

🔘 Now, decide whether the project will be run locally or via Docker.

💽 Locally
  1. Make sure you have Node.js installed in version 16 or higher. Check out the official documentation for more information.

  2. In the project root, install the project dependencies.

npm install
  1. Set up the environment variables:
  • Rename the .env.example file (available in the project root) to .env;
  • Set the variables for your local environment.
  1. Create the database with the command below.
npm run migration
  1. Populate the database with the command below.
npm run seed

ℹ️ The migration.sql and seed.sql files were created and provided by Trybe.

  1. To start the server, use one of the commands below.
// Command 1 - Needs to be run again in case of code changes
npm run start

// Command 2 - Restarts the server automatically if there are any changes in the code
npm run debug
🐋 Docker
  1. Make sure you have docker-compose installed in version 1.29 or higher. Useful links if you need to install or update: DigitalOcean Tutorial and official documentation;

  2. Start the containers by running the command below. Two containers will be started: store_manager (node) and store_manager_db (mysql).

docker-compose up -d
  1. Access the CLI of the store_manager container with the command below or open it in VS Code. For the latter, I recommend the Microsoft extension Dev Containers.
docker exec -it store_manager bash

⚠️ From now on, ALL commands (scripts) available in package.json (including npm install) must be executed INSIDE the store_manager container.

  1. Install the project's dependencies.
npm install
  1. Create the database with the command below.
npm run migration
  1. Populate the database with the command below.
npm run seed

ℹ️ The migration.sql and seed.sql files were created and provided by Trybe.

  1. To start the server, use one of the commands below.
// Command 1 - Needs to be run again in case of code changes
npm run start

// Command 2 - Restarts the server automatically if there are any code changes
npm run debug
  • For the local test context, follow the steps below.
  1. Rename the .env.example file (available in the project root) to .env;
  2. Set the variables for your local environment.

Endpoints

Below you can find a breakdown of the endpoints used in the project. To make HTTP requests and check the behavior of each endpoint, you can use the Thunder Client extension.

Products

GET /products

  • Returns all products registered in the database.
  • URL: http://localhost:PORT/products

POST /products

  • Adds a new product to the database.
  • URL: http://localhost:PORT/products
  • The request body must follow the format below:
{
  "name": "string"
}

GET /products/search

  • Returns all products whose name contains the search term passed in the query.
  • Example URL: http://localhost:PORT/products/search?q=Martelo

GET /products/:id

  • Returns the product whose id was passed in the URL.
  • Example URL: http://localhost:PORT/products/1

PUT /products/:id

  • Updates the product whose id was passed in the URL.
  • Example URL: http://localhost:PORT/products/1
  • The request body must follow the format below:
{
  "name": "string"
}

DELETE /products/:id

  • Removes from the database the product whose id was passed in the URL.
  • Example URL: http://localhost:PORT/products/1

Sales

GET /sales

  • Returns all sales registered in the database.
  • URL: http://localhost:PORT/sales

POST /sales

  • Adds a new sale to the database.
  • URL: http://localhost:PORT/sales
  • The request body must follow the format below:
[
  {
    "productId": number,
    "quantity": number
  },
  {
    "productId": number,
    "quantity": number
  }
]

GET /sales/:id

  • Returns the sale whose id was passed in the URL.
  • Example URL: http://localhost:PORT/sales/1

PUT /sales/:id

  • Updates the sale whose id was passed in the URL.
  • Example URL: http://localhost:PORT/sales/1
  • The request body must follow the format below:
[
  {
    "productId": number,
    "quantity": number
  },
  {
    "productId": number,
    "quantity": number
  }
]

DELETE /sales/:id

  • Removes from the database the sale whose id was passed in the URL.
  • Example URL: http://localhost:PORT/sales/1


About Trybe

"Trybe is a future school for anyone who wants to improve their lives and build a successful career in technology, where the person only pays when they get a good job."

"The program features over 1,500 hours of online classes covering introduction to software development, front-end, back-end, computer science, software engineering, agile methodologies, and behavioral skills."


Contact

Project developed by Guilherme Garcia. Below are my social networks and means of contact. 🤘

Gmail Linkedin GitHub Instagram

Back to top

About

RESTful API for dropshipping sales management. Developed in Node.js with MySQL and MSC architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published