Вы находитесь на странице: 1из 60

[EDMTDEV] MY RESTAURANT API

MY RESTAURANT API DOCUMENT


Author : eddydn aka LinhNTH
Version : 1.0
Last Update: 05/26/2019
YouTube: https://wWw.youtube.com/eddydn71

EDDYDN@GMAIL.COM 1
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 2
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 3
[EDMTDEV] MY RESTAURANT API

I. Introduction
This document is a document of the specification of the My Restaurant
project, a project of a long series of lectures designed to support food ordering from
a variety of combined restaurants.
All assets and documents used in the project are provided free of charge
by EddyDn in the teaching process. Any details can be tracked at
wWw.youtube.com/eddydn71
MyRestaurant project is a passionate project of EddyDn, built for the series
of mobile application development series on Android operating system, through this
series you will learn how:
- Write Backend with NodeJS (support MSSQL or MySQL)
- Write Frontend with Android Studio (Maybe have Kotlin version)
Main features of the application
- Splash Screen
- Login / Logout with Facebook Account Kit
- View multiple restaurant
- Search nearby restaurant on MAP (support by Backend)
- Multiple categories
- Category can be dynamic change for any restaurant
- Multiple foods
- Food can be dynamic change for any Category
- Room persistence + RxJava use for Cart (client save)
- Retrofit + RxJava use for API request
- Support Online Payment (Braintree)
- Each Restaurant can be have each Payment gateway
- API support both MySQL and MSSQL
- Notification between Client / Restaurant App
- Each restaurant will have each account to manager
- Food can be have size , addon

EDDYDN@GMAIL.COM 4
[EDMTDEV] MY RESTAURANT API

Software Requirements:
a. Backend NodeJS + MSSQL
- Microsoft SQL Server 2017
- Microsoft SQL Server Management 18.0 (If you want to work with
- Visual Studio 2019 (NodeJS development)
- Android Studio 3.4.1 (latest)

b. Backend NodeJS + MySQL


- XAMPP 7.3.5
- Visual Studio 2019 (NodeJS development)
- Android Studio 3.4 (latest)

EDDYDN@GMAIL.COM 5
[EDMTDEV] MY RESTAURANT API

I. Database
In this version , I will show you my own first design of Database

EDDYDN@GMAIL.COM 6
[EDMTDEV] MY RESTAURANT API

a. User
This table will contain basic information about the user

MSSQL

MySQL

EDDYDN@GMAIL.COM 7
[EDMTDEV] MY RESTAURANT API

b. Restaurant
This table will contain basic information about the restaurant ,
‘UserOwner’ is Id of RestaurantOwner user . This will help
restaurant can be manage by multiple user

MSSQL

MySQL

EDDYDN@GMAIL.COM 8
[EDMTDEV] MY RESTAURANT API

c. RestaurantOwner
This table will contain user , but this user owner restaurant or is
staff of restaurant

MSSQL

MySQL

EDDYDN@GMAIL.COM 9
[EDMTDEV] MY RESTAURANT API

d. Menu
This table will contain all information about Menu

MSSQL

MySQL

EDDYDN@GMAIL.COM 10
[EDMTDEV] MY RESTAURANT API

e. Food
This table will contain all information of Food

MSSQL

MySQL

EDDYDN@GMAIL.COM 11
[EDMTDEV] MY RESTAURANT API

f. Menu_Food
This table will help us can create multiple food for multiple menu

MSSQL

MySQL

g. Restaurant_Menu
This table will help us can create multiple menu for multiple
restaurant

MSSQL

MySQL

EDDYDN@GMAIL.COM 12
[EDMTDEV] MY RESTAURANT API

h. Size
This table will contain size of food (Some food have size like
Pizza)

MSSQL

MySQL

EDDYDN@GMAIL.COM 13
[EDMTDEV] MY RESTAURANT API

i. Addon
This table will contain addon of food (Some food can be choose
addon like Pizza with special sauce)

MSSQL

MySQL

EDDYDN@GMAIL.COM 14
[EDMTDEV] MY RESTAURANT API

j. Food_Size
This table will help food can be multiple size

MSSQL

MySQL

k. Food_Addon
This table will help food can be multiple addon

MSSQL

MySQL

EDDYDN@GMAIL.COM 15
[EDMTDEV] MY RESTAURANT API

l. Order
This table will contain all information about order of user

MSSQL

MySQL

EDDYDN@GMAIL.COM 16
[EDMTDEV] MY RESTAURANT API

m. OrderDetail
This table will contain all detail of order

MSSQL

MySQL

EDDYDN@GMAIL.COM 17
[EDMTDEV] MY RESTAURANT API

n. Favorite
This table will contain all information about Food Favorite of User

MSSQL

MySQL

EDDYDN@GMAIL.COM 18
[EDMTDEV] MY RESTAURANT API

II. API Document


All API need request to :
http://localhost:3000 => Main Endpoint on Computer
http://10.0.2.2:3000 => Main Endpoint on Emulator Android

Tool use for test:


- Google Chrome (Web Browser)
- AdvancedRestClient (Chrome Exentions)
- Postman (option)

GET ALL USER

Endpoin Method Query Body


t
/user GET key
fbid
Example: http://localhost:3000/user?key=YOUR_API_KEY&userPh
one=%2b0988888888
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing user_phone query in


url"}
Reason: Missing fbid in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result":[{"userPhone":"+84988353682","
name":"Eddy","address":"123444"}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 19
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 20
[EDMTDEV] MY RESTAURANT API

GET ALL RESTAURANT

Endpoint Method Query Body


/restaurant GET key
Example: http://localhost:3000/restaurant?key=YOUR_API_KEY
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 21
[EDMTDEV] MY RESTAURANT API

GET ALL RESTAURANT BY ID

Endpoint Method Query Body


/restaurant GET Key
ById restaurantId
Example: http://localhost:3000/restaurantById?key=YOUR_API_K
EY&restaurantId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing restaurantId field in


query","result":null}
Reason: Missing restaurantId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 22
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 23
[EDMTDEV] MY RESTAURANT API

GET FAVORITES BY FBID

Endpoi Method Query Body


nt
/favorite GET Key
fbid
Example http://localhost:3000/favorite?key=YOUR_API_KEY&fbid
: =xxxx
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing restaurantId field in


query","result":null}
Reason: Missing fbid in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 24
[EDMTDEV] MY RESTAURANT API

Example use with Advanced Client

EDDYDN@GMAIL.COM 25
[EDMTDEV] MY RESTAURANT API

GET FAVORITES BY RESTAURANT

Endpoint Method Query Body


/favoriteByRes GET Key
taurant Fbid
restaurantId
Example: http://localhost:3000/
favoriteByRestaurant?key=YOUR_API_KEY&fbid=
xxxx&restaurantId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing fbid field in


query","result":null}
Reason: Missing fbid in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 26
[EDMTDEV] MY RESTAURANT API

Example use with Advanced Rest Client

EDDYDN@GMAIL.COM 27
[EDMTDEV] MY RESTAURANT API

GET NEARBY RESTAURANT

Endpoint Method Query Body


/nearbyrestaurant GET Key
Lat
Lng
Distance

Example: http://localhost:3000/
nearbyrestaurant?key=YOUR_API_KEY&lat=
30.328820&lng= -81.485750&distance=10
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing lat or lng field in


query","result":null}
Reason: Missing key Lat or Lng in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 28
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 29
[EDMTDEV] MY RESTAURANT API

GET ALL MENU BY RESTAURANT

Endpoint Method Query Body


/menu GET Key
restaurantId
Example: http://localhost:3000/
menu?key=YOUR_API_KEY& restaurantId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing restaurantId field in


query","result":null}
Reason: Missing key restaurantId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 30
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 31
[EDMTDEV] MY RESTAURANT API

GET ALL FOOD BY MENU

Endpoint Method Query Body


/food GET Key
menuId
Example: http://localhost:3000/
food?key=YOUR_API_KEY& menuId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing menuId field in


query","result":null}
Reason: Missing key menuId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 32
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 33
[EDMTDEV] MY RESTAURANT API

GET FAVORITE BY USER

Endpoint Method Query Body


/favorite GET Key
fbid
restaurantId
Example: http://localhost:3000/
food?key=YOUR_API_KEY&
fbid=xxx&restaurantId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing menuId field in


query","result":null}
Reason: Missing key foodName in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 34
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 35
[EDMTDEV] MY RESTAURANT API

GET LIST FAVORITE ID BY FBID AND RESTAURANT

Endpoint Method Query Body


/favoriteByRestaurant GET Key
fbid
restaurantId
Example: http://localhost:3000/
food?key=YOUR_API_KEY&
fbid=xxx&restaurantId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing menuId field in


query","result":null}
Reason: Missing key foodName in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 36
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 37
[EDMTDEV] MY RESTAURANT API

SEARCH FOOD BY NAME

Endpoint Method Query Body


/searchfood GET Key
foodName
Example: http://localhost:3000/
food?key=YOUR_API_KEY& menuId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing menuId field in


query","result":null}
Reason: Missing key foodName in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 38
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 39
[EDMTDEV] MY RESTAURANT API

GET FOOD BY ID

Endpoint Method Query Body


/foodById GET Key
foodId
Example: http://localhost:3000/
food?key=YOUR_API_KEY& foodId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing foodId field in


query","result":null}
Reason: Missing key foodId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 40
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 41
[EDMTDEV] MY RESTAURANT API

GET ALL SIZE BY FOOD

Endpoint Method Query Body


/size GET Key
foodId
Example: http://localhost:3000/ size?key=YOUR_API_KEY&
foodId =1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing foodId field in


query","result":null}
Reason: Missing key foodId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 42
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 43
[EDMTDEV] MY RESTAURANT API

GET ALL ADDON BY FOOD

Endpoint Method Query Body


/addon GET Key
foodId
Example: http://localhost:3000/addon?key=YOUR_API_KEY&
foodId =1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing foodId field in


query","result":null}
Reason: Missing key foodId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 44
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 45
[EDMTDEV] MY RESTAURANT API

GET ALL ORDER BY USER

Endpoint Method Query Body


/order GET Key
orderPhone
Example: http://localhost:3000/order?key=YOUR_API_KEY&
orderPhone =%2B988888888
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing orderPhone field in


query","result":null}
Reason: Missing key orderPhone in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 46
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 47
[EDMTDEV] MY RESTAURANT API

GET ALL ORDER DETAIL BY ORDER

Endpoint Method Query Body


/orderdetail GET Key
orderId
Example: http://localhost:3000/
orderdetail?key=YOUR_API_KEY& orderId =54
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing orderId field in


query","result":null}
Reason: Missing key orderId in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}
- {"success":false,"message":"Empty"}

EDDYDN@GMAIL.COM 48
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 49
[EDMTDEV] MY RESTAURANT API

CREATE OR UPDATE USER

Endpoint Method Query Body


/user POST Key
userPhone
userName
userAddress
fbid
Example: http://localhost:3000/user
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

{"success":false,"message":"Missing userPhone
- field in query","result":null}
Reason: Missing key userPhone
in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"Success”}

EDDYDN@GMAIL.COM 50
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

EDDYDN@GMAIL.COM 51
[EDMTDEV] MY RESTAURANT API

CREATE NEW ORDER NUMBER BY USER

Endpoint Method Query Body


/createOrder POST Key
orderFBID
orderPhone
orderName
orderAddress
orderDate
restaurantId
transactionId
cod
totalPrice
numOfItem
Example: http://localhost:3000/ createOrder
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

- {"success":false,"message":"Missing orderPhone field in


query","result":null}
Reason: Missing key orderPhone in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}

EDDYDN@GMAIL.COM 52
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

If COD = 1 (TRUE) , so we can don’t care about TransactionId , we can put it


NONE
If COD = 0 (FALSE) , we must add transactionId , transactionId will return from
Braintree when you make payment in app

EDDYDN@GMAIL.COM 53
[EDMTDEV] MY RESTAURANT API

ADD ORDER DETAIL FOR ORDER

Endpoint Method Query Body


/updateOrder POST Key
orderId
orderDetail
Example: http://localhost:3000/ updateOrder
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

{"success":false,"message":"Missing orderId
- field in query","result":null}
Reason: Missing key orderId
in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"Success”}

EDDYDN@GMAIL.COM 54
[EDMTDEV] MY RESTAURANT API

Example use in Advanced Rest Client

#Note: orderDetail field is an JSON object of all detail of Information


In this example I use :
[{"foodAddon":"[{\"extraPrice\":5.0,\"id\":2,\"name\":\"Special Sauce
02\"},{\"extraPrice\":5.0,\"id\":3,\"name\":\"Special Sauce
03\"}]","foodExtraPrice":14.0,"foodId":39,"foodImage":"http://10.0.2.2:3000/21_
mushroom_pizza.jpg","foodName":"MUSHROOM
PIZZA","foodPrice":25.0,"foodQuantity":2,"foodSize":"Large","restaurantId":1,"
userPhone":"+84988353682"}]
Parse it by JSON to understandable

EDDYDN@GMAIL.COM 55
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 56
[EDMTDEV] MY RESTAURANT API

CREATE NEW FAVORITE

Endpoint Method Query Body


/favorite POST Key
fbid
foodId
restaurantId
restaurantName
foodName
foodImage
price

Example: http://localhost:3000/ createOrder


Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

{"success":false,"message":"Missing fbid field in query","result":null}


Reason: Missing key fbid in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"result…}]}

EDDYDN@GMAIL.COM 57
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 58
[EDMTDEV] MY RESTAURANT API

DELETE Favorite

Endpoi Method Query Body


nt
/favorit DELETE Key
e fbid
foodId
restaurantId
Exampl http://localhost:3000/favorite?key=xxx&fbid=xxx&foodId=1
e: &restaurantId=1
Error:
- {"success":false,"message":"Wrong API","result":null}
Reason: Missing key (API key) in query

{"success":false,"message":"Missing orderId
- field in query","result":null}
Reason: Missing key orderId
in query

- {"success":false,"message":"…"}
Reason: error from server

Result:
- {"success":true,"Success”}

EDDYDN@GMAIL.COM 59
[EDMTDEV] MY RESTAURANT API

EDDYDN@GMAIL.COM 60

Вам также может понравиться