Coder Social home page Coder Social logo

candycosts's Introduction

CandyCost ๐Ÿ’ป

nodejs typescript express mongo

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.

๐Ÿš€ Getting started

See below for instructions on how to run this project locally.

Prerequisites

Prerequisites required to execute the project:

Cloning

How to clone this project

git clone https://github.com/emersonbbezerra/candycosts.git

Environment Variables

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

Installing

How to install the dependencies of this project.

cd candycosts
npm install

Starting

How to start.

npm run dev

The api will start on port 3000.

๐Ÿ“ API Endpoints

This api covers two route branches: /ingredients and /products

Ingredients Routes

โ€‹

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

POST /ingredients

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."
}

GET /ingredients

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
  }
]

GET /ingredients/663fe25b76042a97733486cb

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."
}

PATCH /ingredients/663fe25b76042a97733486cb

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."
}

DELETE /ingredients/663fe25b76042a97733486cb

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."
}

Products Routes

โ€‹

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

POST /products

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."
}

GET /products

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
  }
]

GET /products/6643dfb05bdf22de8c852bcc

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."
}

PATCH /products/6643dfb05bdf22de8c852bcc

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)"
}

DELETE /products/6643dfb05bdf22de8c852bcc

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."
}

๐Ÿค Collaborators

Be part of this project and appear here in the hall of fame!

Emerson Bezerra
Emerson Bezerra (Creator)
Elon Musk Picture
Elon Musk
Foto do Steve Jobs
Steve Jobs

๐Ÿ“ซ Contribute

Thank you for considering contributing to CandyCost! To contribute, please follow these steps:

  1. 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.

  2. Clone the repository: Clone your forked repository to your local machine using:

    git clone https://github.com/your-username/candycosts.git
  3. Create a new branch: Create a new branch for your feature or bugfix using:

    git checkout -b feature-or-bugfix-name
  4. Make your changes: Make the necessary changes to the codebase.

  5. Commit your changes: Commit your changes with a descriptive commit message using:

    git commit -m "Description of the feature or bugfix"
  6. Push your changes: Push your changes to your forked repository using:

    git push origin feature-or-bugfix-name
  7. 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.

Documentations that might help

๐Ÿ“ How to create a Pull Request

๐Ÿ’พ Commit pattern

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

candycosts's People

Contributors

emersonbbezerra avatar

Watchers

 avatar

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.