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.
ℹ️ Image created and provided by Trybe.
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 aN:N
relationship betweenproducts
andsales
and has the following structure:sale_id product_id quantity 1 1 5
- Create, list, update, and delete products.
- Create, list, update, and delete sales.
To run the project, follow the steps below.
- Clone the repository;
git clone git@github.com:garciaagui/store-manager.git
- Navigate to the root of the project;
cd store-manager/
🔘 Now, decide whether the project will be run locally or via Docker.
💽 Locally
-
Make sure you have Node.js installed in version 16 or higher. Check out the official documentation for more information.
-
In the project root, install the project dependencies.
npm install
- Set up the environment variables:
- Rename the
.env.example
file (available in the project root) to.env
; - Set the variables for your local environment.
- Create the database with the command below.
npm run migration
- Populate the database with the command below.
npm run seed
ℹ️ The
migration.sql
andseed.sql
files were created and provided by Trybe.
- 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
-
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;
-
Start the containers by running the command below. Two containers will be started:
store_manager
(node) andstore_manager_db
(mysql).
docker-compose up -d
- 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 inpackage.json
(including npm install) must be executed INSIDE thestore_manager
container.
- Install the project's dependencies.
npm install
- Create the database with the command below.
npm run migration
- Populate the database with the command below.
npm run seed
ℹ️ The
migration.sql
andseed.sql
files were created and provided by Trybe.
- 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.
- Rename the
.env.example
file (available in the project root) to.env
; - Set the variables for your local environment.
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
- Returns all products registered in the database.
- URL:
http://localhost:PORT/products
- Adds a new product to the database.
- URL:
http://localhost:PORT/products
- The request body must follow the format below:
{
"name": "string"
}
- Returns all products whose name contains the search term passed in the query.
- Example URL:
http://localhost:PORT/products/search?q=Martelo
- Returns the product whose id was passed in the URL.
- Example URL:
http://localhost:PORT/products/1
- 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"
}
- Removes from the database the product whose id was passed in the URL.
- Example URL:
http://localhost:PORT/products/1
Sales
- Returns all sales registered in the database.
- URL:
http://localhost:PORT/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
}
]
- Returns the sale whose id was passed in the URL.
- Example URL:
http://localhost:PORT/sales/1
- 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
}
]
- Removes from the database the sale whose id was passed in the URL.
- Example URL:
http://localhost:PORT/sales/1
"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."
Project developed by Guilherme Garcia. Below are my social networks and means of contact. 🤘