Getting Started โข API Endpoints โข Collaborators โข Contribute
This is a personal project that I am developing for my wife, who owns a small bakery and works only to order. It's an API for registering ingredients and products it manufactures. It calculates the cost of a given recipe (cake, dessert, sweet, etc.) based on the ingredients and their respective quantities used in preparation.
See below for instructions on how to run this project locally.
Prerequisites required to execute the project:
How to clone this project
git clone https://github.com/emersonbbezerra/candycosts.git
Use the code below as a reference to create your .env
configuration file by adding your MongoDB URL.
DATABASE_URL=add_your_mongodb_connection_string_here
How to install the dependencies of this project.
cd candycosts
npm install
How to start.
npm run dev
The api will start on port 3000.
This api covers two route branches: /ingredients
and /products
โ
route | description |
---|---|
POST /ingredients | register an ingredient in the database post details |
GET /ingredients | list registered ingredients response details |
GET /ingredients/:id | returns the ingredient by id response details |
PATCH /ingredients/:id | update the ingredient by id patch details |
DELETE /ingredients/:id | delete the ingredient by id response details |
REQUEST
{
"name": "Cocoa Powder",
"manufacturer": "Now Foods",
"price": "10",
"unit": "Kg"
}
RESPONSE
{
"message": "Ingredient registered successfully."
}
If there is already an ingredient registered with the same name and the same manufacturer in the database, the API will return the error:
{
"status": 400,
"message": "There is already a similar ingredient registered."
}
RESPONSE
[
{
"_id": "663fe21776042a97733486c7",
"name": "Cocoa Powder",
"manufacturer": "Now Foods",
"price": 10,
"unit": "Kg",
"createdAt": "2024-05-11T21:24:39.889Z",
"__v": 0
},
{
"_id": "663fe25b76042a97733486cb",
"name": "Wheat flour",
"manufacturer": "Best Flour",
"price": 5,
"unit": "Kg",
"createdAt": "2024-05-11T21:25:47.044Z",
"__v": 0
},
{
"_id": "663fe29f76042a97733486cf",
"name": "Sugar",
"manufacturer": "Sweetness",
"price": 3.99,
"unit": "Kg",
"createdAt": "2024-05-11T21:26:55.801Z",
"__v": 0
}
]
RESPONSE
{
"_id": "663fe25b76042a97733486cb",
"name": "Wheat flour",
"manufacturer": "Best Flour",
"price": 5.1,
"unit": "Kg",
"createdAt": "2024-05-11T21:25:47.044Z",
"__v": 0
}
If the ingredient with the specified ID is not found, the API will return the error:
{
"status": 404,
"message": "Ingredient not found."
}
REQUEST
You can update the following data in an ingredient: name
, manufacturer
, price
and unit
.
It's possible to update just one piece of data at a time or all of the data for an ingredient.
{
"price": 6
}
Or
{
"unit": "lbs"
}
RESPONSE
{
"message": "Ingredient updated successfully."
}
If the name and manufacturer are updated and there is already a similar one in the database, the API will return the error:
{
"status": 400,
"message": "There is already a similar ingredient registered."
}
RESPONSE
{
"message": "Ingredient deleted successfully."
}
If the ingredient with the specified ID is not found, the API will return the error:
{
"status": 404,
"message": "Ingredient not found."
}
โ
route | description |
---|---|
POST /products | register an product in the database post details |
GET /products | list registered products response details |
GET /products/:id | returns the product by id response details |
PATCH /products/:id | update the product by id patch details |
DELETE /products/:id | delete the product by id response details |
REQUEST
{
"name": "Chocolate Cake",
"description": "Traditional cocoa dough.",
"ingredients": [
{ "ingredientId": "663fe21776042a97733486c7", "amount": 2 },
{ "ingredientId": "663fe29f76042a97733486cf", "amount": 2 },
{ "ingredientId": "663fe2de76042a97733486d5", "amount": 2 },
{ "ingredientId": "663fe32976042a97733486db", "amount": 2 }
]
}
RESPONSE
{
"message": "Product registered successfully."
}
If there is already an product registered with the same name in the database, the API will return the error:
{
"message": "There is already a product registered with that name."
}
RESPONSE
[
{
"_id": "6643d83675c8e4f5f7543e1a",
"name": "Chocolate Cake",
"description": "Traditional cocoa dough.",
"ingredients": [
{
"ingredientId": "663fe21776042a97733486c7",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d79"
},
{
"ingredientId": "663fe29f76042a97733486cf",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7a"
},
{
"ingredientId": "663fe2de76042a97733486d5",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7b"
},
{
"ingredientId": "663fe32976042a97733486db",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7c"
}
],
"cost": 77.72,
"createdAt": "2024-05-20T14:11:11.077Z",
"__v": 0
},
{
"_id": "6643dfb05bdf22de8c852bcc",
"name": "Coconut cake",
"description": "Cake with creamy coconut filling.",
"ingredients": [
{
"ingredientId": "663fe21776042a97733486c7",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d79"
},
{
"ingredientId": "663fe29f76042a97733486cf",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7a"
},
{
"ingredientId": "663fe2de76042a97733486d5",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7b"
},
{
"ingredientId": "663fe32976042a97733486db",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7c"
}
],
"cost": 38.86,
"createdAt": "2024-05-20T14:11:11.077Z",
"__v": 0
}
]
RESPONSE
{
"_id": "6643dfb05bdf22de8c852bcc",
"name": "Coconut cake",
"description": "Cake with creamy coconut filling.",
"ingredients": [
{
"ingredientId": "663fe21776042a97733486c7",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d79"
},
{
"ingredientId": "663fe29f76042a97733486cf",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7a"
},
{
"ingredientId": "663fe2de76042a97733486d5",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7b"
},
{
"ingredientId": "663fe32976042a97733486db",
"amount": 2,
"_id": "664b59ffa5f9f4fc1eb21d7c"
}
],
"cost": 38.86,
"createdAt": "2024-05-20T14:11:11.077Z",
"__v": 0
}
If the product with the specified ID is not found, the API will return the error:
{
"status": 404,
"message": "Product not found."
}
REQUEST
You can update the following data in an product: name
, description
and ingredients
.
It's possible to update just one piece of data at a time or all of the data for an product.
{
"name": "Creamy Coconut Cake"
}
Or
{
"ingredients": [
{
"ingredientId": "663fe21776042a97733486c7",
"amount": 1.5,
"_id": "664b59ffa5f9f4fc1eb21d79"
},
{
"ingredientId": "663fe29f76042a97733486cf",
"amount": 2.5,
"_id": "664b59ffa5f9f4fc1eb21d7a"
},
{
"ingredientId": "663fe2de76042a97733486d5",
"amount": 1,
"_id": "664b59ffa5f9f4fc1eb21d7b"
},
{
"ingredientId": "663fe32976042a97733486db",
"amount": 0.5,
"_id": "664b59ffa5f9f4fc1eb21d7c"
}
]
}
RESPONSE
{
"message": "Product updated successfully."
}
If the request is to update the product name, it cannot be the same as one previously registered. If it already exists in the database, the API will return the error:
{
"status": 400,
"message": "There is already a product registered with that name. His id is: (here it shows the id of the existing product)"
}
RESPONSE
{
"message": "Product deleted successfully."
}
If the product with the specified ID is not found, the API will return the error:
{
"status": 404,
"message": "Product not found."
}
Be part of this project and appear here in the hall of fame!
Emerson Bezerra (Creator) |
Elon Musk |
Steve Jobs |
Thank you for considering contributing to CandyCost! To contribute, please follow these steps:
-
Fork the repository: Click on the 'Fork' button at the top right of this page to create a copy of the repository in your GitHub account.
-
Clone the repository: Clone your forked repository to your local machine using:
git clone https://github.com/your-username/candycosts.git
-
Create a new branch: Create a new branch for your feature or bugfix using:
git checkout -b feature-or-bugfix-name
-
Make your changes: Make the necessary changes to the codebase.
-
Commit your changes: Commit your changes with a descriptive commit message using:
git commit -m "Description of the feature or bugfix"
-
Push your changes: Push your changes to your forked repository using:
git push origin feature-or-bugfix-name
-
Create a Pull Request: Open a Pull Request to merge your changes into the main repository. Make sure to include a detailed description of your changes.
๐ How to create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.