Skip to content

NicholasLawrence/CIET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Can I Eat This API (CIET)

N|Solid

CIET is a mobile application that will let users navigate through the menu of a restaurant and be alerted to foods that they may be allergic to. The API is compatible with JSON.

  • Specify your allergies
  • View a restaurant's menu
  • View dish & related allergies

REST API v 2.0.0

CIET uses a number of open source projects to work properly:

  • Underscore.js - functional programming helpers without extending any built-in objects.
  • mongoDB - open-source, document database designed for ease of development and scaling
  • mongoose - object modeling tool designed to work in an asynchronous environment.
  • node.js - evented I/O for the backend
  • restify - node.js module built specifically to enable you to build correct REST web services.

Installation

CIET requires Node.js v6.9.1+ to run. The database is hosted on mLab, connection details are embedded in the included config.json file.

Install the dependencies and devDependencies and start the server.

$ cd API
$ npm install -d
$ node host.js

Specification / Request Documentation

By default, the app will expose port 8080, so change this within the host.js file if necessary.

Get User Preferences

View saved allergies and feedback.

Request
  • id: User ID
GET http://localhost:8080/user/:id/preferences
Response
[
  {
    "_id": 1,
    "information_is_useful": true,
    "will_use_app_in_future": true,
    "allergies": [
      {
        "allergy_id": {
          "_id": 1,
          "name": "Nut (Peanut)"
        },
        "severity": "Minor"
      },
      {
        "allergy_id": {
          "_id": 2,
          "name": "Milk"
        },
        "severity": "Moderate"
      },
      {
        "allergy_id": {
          "_id": 3,
          "name": "Egg"
        },
        "serverity": "Dangerous"
      }
    ]
  }
]

Upsert User Preferences

Inset or Update (if exists) user saved allergies and feedback.

Request
  • id: User ID
PUT http://localhost:8080/user/:id/preferences
[
  {
    "_id": 1,
    "information_is_useful": true,
    "will_use_app_in_future": true,
    "allergies": [
      {
        "allergy_id": 1,
        "severity": "Minor"
      },
      {
        "allergy_id": 2,
        "severity": "Moderate"
      },
      {
        "allergy_id": 3,
        "serverity": "Dangerous"
      }
    ]
  }
]
Response

HTTP Response Code

Get Restaurant Menus

The items on the menu will show the name and image of the dish, a brief description of the dish, the main ingredients, a list of severe allergy risks, and whether the user is allergic to an item in the dish and the severity.

Request
  • user_id: [Required] User ID
  • last_menu_id: Used for paging through restaurant menus. V aluerestaurant menu at the end of last request or 0 to start at the beginning.
  • limit: Number of restaurant menus to return.
GET http://localhost:8080/menu/:last_menu_id/:limit?user_id=:user_id
Response
[
  {
    "_id": 1,
    "items": [
      {
        "image": "aaaaa.jpg",
        "name": "Stuffed Chicken",
        "description": "The stuffing used in this chicken is a good option for gluten-intolerant eaters.",
        "ingredients": [
          "jasmine rice",
          "golden sultanas",
          "red onion",
          "chicken stock",
          "butter",
          "black pepper",
          "chicken",
          "pine nuts",
          "lemons",
          "italian parsley",
          "olive oil"
        ],
        "allergy_risks": [
          {
            "allergy_id": {
              "_id": 1,
              "name": "Nut (Peanut)"
            },
            "severity": "High",
            "userHasAllergy": true,
            "userAllergySeverity": "Minor"
          },
          {
            "allergy_id": {
              "_id": 2,
              "name": "Milk"
            },
            "severity": "Medium",
            "userHasAllergy": true,
            "userAllergySeverity": "Moderate"
          }
        ]
      },
      {
        "image": "aaaab.jpg",
        "name": "Eggplant Salad",
        "description": "We like to serve the eggplant salad warm but it is just as delicious served at room temperature.",
        "ingredients": [
          "eggplants",
          "oregano",
          "olive oil",
          "pomegrante seed",
          "tomatoes",
          "basil leaves"
        ],
        "allergy_risks": []
      },
      {
        "image": "aaaac.jpg",
        "name": "Salad Dressing",
        "description": "Eggplant Salad Dressing",
        "ingredients": [
          "sherry vinegar",
          "pomegranate molasses",
          "olive oil"
        ],
        "allergy_risks": []
      }
    ]
  }
]

Get Menu Item Image

Returns the image for a menu item/dish

Request
  • filename: name of the image with extension. eg. aaaaa.jpg
GET http://localhost:8080/Images/:filename
Response

Image

Get Foursquare Venues : Version 2.0.0

Restaurant/Venue data which originates from Foursquare

Request
  • limit: limit number of results (max: 50)
  • offset: skip this number of results,
  • time: Pass any to retrieve results for any time of day. Omitting this parameter returns results targeted to the current time of day.
  • day: Pass any to retrieve results for any day of the week. Omitting this parameter returns results targeted to the current day of the week.
  • openNow: Boolean flag to only include venues that are open now
  • venuePhotos: Boolean flag to include a photo in the response for each venue, if one is available. Default is 0 (no photos). Photos are returned as part of the venue JSON object.
  • price: Comma separated list of price points. Currently the valid range of price points are [1,2,3,4], 1 being the least expensive, 4 being the most expensive. For food venues, in the United States, 1 is < $10 an entree, 2 is $10-$20 an entree, 3 is $20-$30 an entree, 4 is > $30 an entree.,
  • specials: Boolean flag to only include venues that have a special.
GET http://localhost:8080/restaurant
Response

Omitted due to size

Todos

  • Write Tests
  • Add Code Comments
  • Implement referential integrity checks on Allergy Data
  • Validate request parameters
  • Search by restaurant once CTO finishes restaurant & venue implementation
  • Improve static image serving regex for security
  • Set proper HTTP Headers, especially content-type and CORS
  • Swap out MongoDB's deprecated promise framework
  • Encrypt config data

Assumptions

  • Menu Item/Dish images are requested separately to accomodate caching in future modifications
  • Restaurant & Venue data was not tagged to Menu since those 2 sections were to be omitted.
  • The CTO wanted to capture how many users found the information useful and will use it in the future.

Apologies

  • Sorry about the shortage of sample data

License

MIT

Free Software, Hell Yeah!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors