Easy Order - louis-xu-ustc/EasyOrder_Backend GitHub Wiki

Easy Order Wiki!

Backend API design

Base URL

http://54.202.127.83/backend

User

  1. create new user / delete user (not used)
http POST <BaseURL>/user/ twitterID=<string> name=<string>
http DELETE <BaseURL>/user/ twitterID=<string>

Dish

  1. post new dish to menu
http POST <BaseURL>/dish/ name=<string> price=<int> photo=<base64 encoded picture>
  1. get all dish information / delete all dish (not used)
http GET <BaseURL>/dish/
[
  {
    "name":"pizza",
    "price":20,
    "rate":3.5,
    "rateNum":3,
    "photo":"/media/dishes/33a797d3-913.jpg",
    "id":1
  },
  {
  ...
  }
]

get rate of dish (provide dish ID) (Duplicated Function)

  1. get/delete certain dish
http GET <BaseURL>/dish/<dishid>
http DELETE <BaseURL>/dish/<dishid>
  1. post rate of dish (one user can only vote once towards a dish)
http PUT  <BaseURL>/rate/<dishid> user=<twitterID> rate=<num>
http DELETE  <BaseURL>/rate/<dishid> user=<twitterID>

Order

  1. post order in one shot / specifying dish type and dish amount as a user
http POST <BaseURL>/order/ twitterID=<twitterID> amount=<num> dish=<dishid>
http POST <BaseURL>/order/bunch

request data:
{
  "twitterID": "21345467",
  "order": [
             {
               "dish": 2,
               "amount": 1,
             },
             ...
           ]
}
  1. get order amount of dish
http GET <BaseURL>/order/
[
  {
    "id": 1,
    "name": "pizza",
    "price": 2,
    "rate": 3.5,
    "photo": "media/dish/a4db.jpg",
    "num": 3
  },
  {
    ...
  }
}

Get effective orders for a user (within this meal interval)

http GET <BaseURL>/order/user/<twitterID>
[
{
    "dish": "pizza",
    "price": 10,
    "amount": 2
},
{
...
}
]

Get history orders (recent 5 order)

http GET <BaseURL>/order/history/<twitterID>
[
  {
    "dish": "pizza",
    "price": 10,
    "amount": 2
  },
  {
    ...
  }
]

Location

  1. update retailer's location
http PUT  <BaseURL>/current_location/ latitude=<num> longitude=<num>
  1. get retailer's location
http GET <BaseURL>/current_location/
{
  "latitude":"10.23",
  "longitude":"102.18"
}
  1. get all pickup location
http GET <BaseURL>/pickup_locations/
[
  {
    "latitude":"10",
    "longitude":"102",
    "name": "CMU"
  },
  {
    ...
  }
]
  1. add a pickup location
http POST <BaseURL>/pickup_locations/ latitude=<num> longitude=<num>
  1. delete all pickup location
http DELETE <BaseURL>/pickup_locations/

Notification

  1. post arrival notification (triggered by geofencing / pressed by retailer)
http PUT <BaseURL>/notification/ content=<string>
  1. get arrival notification (long poll)

    First time GET the notification without timestamp, you would get a notification with its modified time (represented in timestamp). From second REST call (long polling), append timestamp in URI to check whether there is a new notification.

http GET <BaseURL>/notification/
http GET <BaseURL>/notification/<last-timestamp>/
// there is a new notification
{
    "content": "hello",
    "modified_at": "1499745017",
    "notification": true
}
// no new notification
{
    "notification": false
}

Tab3

  1. get the client token that is used for braintree payment
http GET <BaseURL>/payment/client_token/
  1. place the order
http POST <BaseURL>/payment/checkout/         (iOS version, use HTTP POST input)
http POST <BaseURL>/payment/checkout/android/ (android version, use Json input)
// HTTP.body
payment_method_nonce=%<nonce-generated-locally>&user_id=%<twitter-access=token>
  1. get list of users (with whether user has paid) (long poll)
http GET <BaseURL>/user/
[
  {
    "twitterID": "1234567890",
    "name": "Jiajie",
    "paid": True,
  }
  {
    ...
  }
]
⚠️ **GitHub.com Fallback** ⚠️