Welcome to the Project Backend developed as part of the Geração Tech program. This project provides a robust backend API with functionalities for user management, product handling, and category management.
- Getting Started
- Prerequisites
- Installation
- Database Setup
- Testing the Application
- Future Improvements
- Acknowledgments
- Motivational Quote
Ensure that you have the following installed:
-
Clone the Repository:
git clone https://github.com/joaomaxdev/project-backend.git
-
Navigate to the Project Directory:
cd project-backend -
Install Dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root directory and add the following content:DB_HOST=localhost DB_USER=root DB_PASSWORD= DB_NAME=project_root JWT_SECRET=your_secret_key
-
Log in to MySQL:
mysql -u root -p
-
Create the Database:
CREATE DATABASE project_root; CREATE DATABASE project_root_test; CREATE DATABASE project_root_production;
-
Run Migrations:
npx sequelize-cli db:migrate
-
Optional - Create Database Configurations Automatically: You can use the following command to automatically set up the database configurations:
npm run createdb
You can test the API endpoints using tools like Postman or Insomnia.
-
Create a User:
- Endpoint:
POST /v1/user - Request Body:
{ "firstname": "John", "surname": "Doe", "email": "john.doe@example.com", "password": "password123", "confirmPassword": "password123" }- Response: Token will be generated for authentication.
- Endpoint:
-
Update a User:
- Endpoint:
PUT /v1/user/:id - Request Body:
{ "firstname": "John", "surname": "Doe", "email": "john.doe@example.com" }- Headers: Add the token in the Authorization header as a Bearer token.
- Response:
204 No Content.
- Endpoint:
-
Get a User by ID:
- Endpoint:
GET /v1/user/:id - Response:
{ "id": 1, "firstname": "John", "surname": "Doe", "email": "john.doe@example.com" } - Endpoint:
-
Delete a User:
- Endpoint:
DELETE /v1/user/:id - Response:
204 No Content- Success.401 Unauthorized- Invalid token.404 Not Found- User not found.
- Endpoint:
-
Create a Category:
- Endpoint:
POST /v1/category - Request Body:
{ "name": "Shoes", "slug": "shoes", "use_in_menu": true }- Response:
201 Created.
- Endpoint:
-
Get All Categories:
- Endpoint:
GET /v1/category/search
- Endpoint:
-
Get a Category by ID:
- Endpoint:
GET /v1/category/:id
- Endpoint:
-
Update a Category:
- Endpoint:
PUT /v1/category/:id - Request Body:
{ "name": "Shoes", "slug": "shoes", "use_in_menu": true }- Response:
204 No Content.
- Endpoint:
-
Delete a Category:
- Endpoint:
DELETE /v1/category/:id - Response:
204 No Content.
- Endpoint:
-
Create a Product:
- Endpoint:
POST /v1/product - Request Body:
{ "enabled": true, "name": "Product 2", "slug": "product-2", "stock": 10, "description": "Description of Product 2", "price": 250.90, "price_with_discount": 199.90, "category_ids": [1], "images": [ { "type": "image/png", "content": "base64_image_1" }, { "type": "image/png", "content": "base64_image_2" }, { "type": "image/jpg", "content": "base64_image_3" } ], "options": [ { "title": "Color", "shape": "square", "radius": "4px", "type": "text", "values": ["PP", "GG", "M"] }, { "title": "Size", "shape": "circle", "type": "color", "values": ["#000", "#333"] } ] }- Response:
201 Created.
- Endpoint:
-
Get All Products:
- Endpoint:
GET /v1/product/search
- Endpoint:
-
Get a Product by ID:
- Endpoint:
GET /v1/product/:id
- Endpoint:
-
Update a Product:
- Endpoint:
PUT /v1/product/:id - Request Body:
{ "enabled": true, "name": "Updated Product 01", "slug": "updated-product-01", "stock": 20, "description": "Updated description of Product 01", "price": 49.90, "price_with_discount": 0, "category_ids": [1], "images": [ { "type": "image/png", "content": "base64_image_1" }, { "id": 2, "deleted": true }, { "id": 3, "content": "base64_image_3" }, { "id": 1, "content": "https://store.com/media/product-01/image-01.jpg" } ], "options": [ { "id": 1, "deleted": true }, { "id": 2, "radius": "10px", "values": ["42/43", "44/45"] }, { "title": "Type", "shape": "square", "type": "text", "values": ["100% cotton", "65% cotton"] } ] }- Response:
204 No Content.
- Endpoint:
-
Delete a Product:
- Endpoint:
DELETE /v1/product/:id - Response:
204 No Content.
- Endpoint:
Due to time constraints, not all endpoints are complete. Future updates will include additional features and improvements to fully complete the project.
Thank you for your patience. For any questions or further assistance, feel free to reach out.
A special thanks to the Geração Tech program and its mentors for their invaluable support and guidance throughout this project. Your encouragement and feedback were crucial in helping me grow and complete this work.
"The best way to predict the future is to invent it." – Alan Kay
João Max (joaomaxdev) Fullstack Developer