Calorie Tracker Micro-Service

About

Welcome to the Calorie Tracker Micro-Service. This is a micro-service that come with Calorie Tracker, a project completed during the Module 4 of Turing School of Software & Design.

The deployed site's endpoints can be consumed at:

https://calorie-tracker-self-ms.herokuapp.com/

Technique Stack

  • Node.js / Express

  • Squelize / GraphQL

  • Jest / Superset

Endpoints

This service utilizes GraphQL.

/graphql?=query={getAllRecipes{id,name}}

Returns a list of all recipes. Additional attributes should be included as comma separated values without any spacing. Available attributes for getAllRecipes are:

  • id

  • name

  • foodType

  • recipeLink

  • numberOfIngredients

  • totalCalories

  • totalPrepTime

Example of expected output:

{
  "data": {
    "getAllRecipes": [
      {
        "id": "1",
        "name": "Chicken Vesuvio"
      },
      {
        "id": "2",
        "name": "Chicken Gravy"
      },
      {
        "id": "3",
        "name": "Kreplach (Chicken Dumplings)"
      },
      {
        "id": "4",
        "name": "Chicken Marsala"
      }
    ]
  }
}

/graphql?=query={recipeSearch(foodType:"Curry Sauce"){id,name}}

Returns a list of all recipes filtered by food type. A footType argument is required. Additional attributes should be included as comma separated values without any spacing. Available attributes for recipeSearch are:

  • id

  • name

  • foodType

  • recipeLink

  • numberOfIngredients

  • totalCalories

  • totalPrepTime

Example of expected output:

{
  "data": {
    "recipeSearch": [
 {
        "id": "51",
        "foodType": "Curry Sauce",
        "name": "Lobster with Curry Sauce"
      },
      {
        "id": "52",
        "foodType": "Curry Sauce",
        "name": "British Curry Sauce"
      },
      {
        "id": "57",
        "foodType": "Curry Sauce",
        "name": "Tofu with Thai Curry Sauce recipes"
      },
      {
        "id": "53",
        "foodType": "Curry Sauce",
        "name": "Banana-Leaf-Wrapped Grouper with Curry Sauce"
      }
    ]
  }
}

/graphql?=query={totalIngredients(numberOfIngredients:50){id,foodType,name,numberOfIngredients}}

Returns a list of all recipes with the specified number of ingredients. A numberOfIngredients argument is required. Additional attributes should be included as comma separated values without any spacing. Available attributes for totalIngredients are:

  • id

  • name

  • foodType

  • recipeLink

  • numberOfIngredients

  • totalCalories

  • totalPrepTime

Example of expected output:

{
  "data": {
    "totalIngredients": [
      {
        "id": "21",
        "foodType": "Sushi",
        "name": "Perfect Sushi Rice recipes",
        "numberOfIngredients": 4
      },
      {
        "id": "29",
        "foodType": "Sushi",
        "name": "Sushi rolls",
        "numberOfIngredients": 7
      },
      {
        "id": "55",
        "foodType": "Curry Sauce",
        "name": "Coconut Shrimp with Red Curry Sauce",
        "numberOfIngredients": 14
      }
    ]
  }
}

/graphql?=query={totalPrepTime(preparationTime:20){id,foodType,name,preparationTime}}

Returns a list of all recipes with the specified preparation time. A preparationTime argument is required. Additional attributes should be included as comma separated values without any spacing. Available attributes for totalPrepTime are:

  • id

  • name

  • foodType

  • recipeLink

  • numberOfIngredients

  • totalCalories

  • totalPrepTime

Example of expected output:

{
  "data": {
    "totalPrepTime": [
      {
        "id": "40",
        "foodType": "Banana",
        "name": "Banana Rum Cocktail",
        "preparationTime": 20
      },
      {
        "id": "49",
        "foodType": "Plantain Banana",
        "name": "Griddled Banana, Mango, and Jalapeño Sandwiches",
        "preparationTime": 20
      },
      {
        "id": "57",
        "foodType": "Curry Sauce",
        "name": "Tofu with Thai Curry Sauce recipes",
        "preparationTime": 20
      },
      {
        "id": "53",
        "foodType": "Curry Sauce",
        "name": "Banana-Leaf-Wrapped Grouper with Curry Sauce",
        "preparationTime": 20
      }
    ]
  }
}

/graphql?=query={averageCalories(foodType:"Sushi"){average}}

Returns the total average calorie for all recipes with the specified food type. A foodType argument is required. Additional attributes should be included as comma separated values without any spacing. Available attributes for averageCalories are:

  • foodType

  • average

Example of expected output:

{
  "data": {
    "averageCalories": [
      {
        "foodType": "Sushi",
        "average": 1036.9
      }
    ]
  }
}

/graphql?=query={sortIngredients(foodType:"Banana"){id, name, numberOfIngredients}}

Returns a list of all recipes with the specified food type, sorted by the number of ingredients from the least to the greatest. A foodType argument is required. Additional attributes should be included as comma separated values without any spacing. Available attributes for sortIngredients are:

  • id

  • name

  • foodType

  • recipeLink

  • numberOfIngredients

  • totalCalories

  • totalPrepTime

Example of expected output:

{
  "data": {
    "sortIngredients": [
      {
        "id": "34",
        "name": "Banana Snack Wraps recipes",
        "numberOfIngredients": 3
      },
      {
        "id": "38",
        "name": "Chocolate & Banana recipes",
        "numberOfIngredients": 3
      },
      {
        "id": "31",
        "name": "Banana-Blueberry Smoothie",
        "numberOfIngredients": 3
      },
      {
        "id": "40",
        "name": "Banana Rum Cocktail",
        "numberOfIngredients": 4
      },
      {
        "id": "32",
        "name": "Banana in golden syrup",
        "numberOfIngredients": 4
      },
      {
        "id": "39",
        "name": "Banana Pineapple Green Drink",
        "numberOfIngredients": 4
      },
      {
        "id": "37",
        "name": "Banana Cookies recipes",
        "numberOfIngredients": 5
      },
      {
        "id": "33",
        "name": "Campfire Banana Boat Chocolate Caramel S'mores recipes",
        "numberOfIngredients": 5
      },
      {
        "id": "35",
        "name": "Banana Daquiri",
        "numberOfIngredients": 6
      },
      {
        "id": "36",
        "name": "Banana Pudding",
        "numberOfIngredients": 14
      }
    ]
  }
}

/graphql?=query={sortPrepTime(foodType:"Chicken"){id,name,preparationTime}}

Returns a list of all recipes with the specified food type, sorted by the preparation time from the least to the greatest. A foodType argument is required. Additional attributes should be included as comma separated values without any spacing. Available attributes for sortPrepTime are:

  • id

  • name

  • foodType

  • recipeLink

  • numberOfIngredients

  • totalCalories

  • totalPrepTime

Example of expected output:

{
  "data": {
    "sortPrepTime": [
      {
        "id": "3",
        "name": "Kreplach (Chicken Dumplings)",
        "preparationTime": 10
      },
      {
        "id": "9",
        "name": "Chicken Saltimbocca",
        "preparationTime": 35
      },
      {
        "id": "1",
        "name": "Chicken Vesuvio",
        "preparationTime": 60
      },
      {
        "id": "6",
        "name": "Chicken cacciatore",
        "preparationTime": 60
      },
      {
        "id": "10",
        "name": "Easy Chicken Stock",
        "preparationTime": 90
      },
      {
        "id": "8",
        "name": "Chicken Soup",
        "preparationTime": 120
      }
    ]
  }
}

Get Started

Requirements

Clone

$ git clone git@github.com:TheMindset/calorie_tracker.git
$ cd calorie_tracker
$ npm install

Setup Database

  • Create a .env file in the main directory.

  • Define DB_USERNAME within within .env as your Postgres username.

  • Define DB_DATABASE within within .env as calorie_tracker_microservice_development.

  • Run this command from the calorie_tracker_microservice project directory.

$ npx sequelize db:create
$ npx sequelize db:migrate

The database is seeded with the Edaman API. In order to utilize it in this Micro-service you will need:

  • Create an application on the Edaman API website.

  • Define your application's EDAMAN_APP_ID within the .env.

  • Define your application's EDAMAN_APP_KEY within the .env.

  • Seed the database with this command:

$ npx jake fetchData[NAME_OF_YOUR_FAVORITE_FOOD]

❗ If you use zsh

  • Seed the database by adding single quote on the command like this:
$ npx jake 'fetchData[NAME_OF_YOUR_FAVORITE_FOOD]'

API Exploration

Once installation and database setup are complete, explore the various API endpoints with the following steps:

  • From the calorie_tracker_microservice project directory, start up the server $ npm start
  • Open your browser, and visit http://localhost:3000/
  • Query the available endpoints by appending to http://localhost:3000/ in your browser.

Running Tests

You can run the tests implemented with Jest by run this command $ npm test.

Exemple of expected output

Test Suites: 1 passed, 1 total
Tests:       7 passed, 7 total
Snapshots:   0 total
Time:        4.766s
Ran all test suites.