-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSON Specifications.txt
210 lines (179 loc) · 5.48 KB
/
JSON Specifications.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// NOTE: we agreed to use snake case :p
// ** categories vs subcategories issue **
// let's deal with "category" as an abstract concept
// a category is a collection of subcategories
// every product should have a property subcategory: List<subcategory>
// but not a category property
// clicking on subcategory => redirects you to searching with no restriction filtered with the subcategory
// the only place where we would need category:
// category page to display the subcategories
productSummary
{
"id": ...,
"name": ...,
"price": number,
"image": ImageURL,
"discount": float
},
product
{
"id": ...,
"name": ...,
"price": {
"$numberDouble": number
},
"image_list": List<ImageURL>,
"subcategory": List<category>,
"description": a paragraph,
//! backend side edit required here
// rest of properties should be inside the following object
// to put them all in a table
others: {
"unit": ...,
"..." : ...
}
"stock": {
"$numberDouble": "0.0"
},
"discount": {
"$numberDouble": "0.0"
}
},
category
{
"category": ...,
"subcategory": [
"subcat1",
"subcat2",
"subcat3",
]
}
GET $URL/home:
{
slides: List<ImageURL>,
content: [
{
title: sectionTitle,
content: List<productSummary>
},
...
]
}
GET $URL/cat:
[
{
title: sectionTitle,
content: [
{
title: sectionTitle,
image: subsectionImageURL
}
]
}
]
GET $URL/product/ID:
product
GET $URL/search/keyword: Attach admin JWT token to return additional info of stock and subcategories
body
{
"sort": "price+"(Ascending) | "price-"(Descending) | "relevance",
// Optional arguments below
"price_min": Int,
"price_max": Int,
"subcategories": [
"subcat1",
"subcat2",
"subcat3"
]
}
return:
List<productSummary>
POST $URL/auth/signup: Returns the id of user in db
{
"email": "[email protected]",
"password": "grocery-on-rails",
// optional arguments below
"username": "cswpy",
"privilege": true // Default false, do not specify it for normal users
}
POST $URL/auth/login: Returns the JWT token for access, save it for future requests, the token identifies an unique user, use it whenever user information is involved
It also returns username and addresses for all users
{
"email": ...,
"password": ...
}
APIs for Admin, send below requests with a bearer token that belongs to a admin user with privilege
POST $URL/home: Create new product
Follow product specification exactly
Name, Price, Description are required
DELETE $URL/home: Delete a product
{
"id": ...
}
POST $URL/product/<id>: Modify an existing product: it cannot add new keys that is not in the database
{
"key": "value",
}
DELETE $URL/cat: Delete a category
{
"category": ...
}
POST $URL/cat/<categoryname>: Add multiple subcats to the category
{
"subcategory": [
"subcat1",
"subcat2",
...
]
}
DELETE $URL/cat/<categoryname>: Delete one subcat from the category
{
"name": subcat1
}
GET $URL/admin/orders: get all orders from all users
POST $URL/admin/orders: modify an order
body
{
"order_id": "...",
// Optional arguments below
"status": "delivered"/"pending"/"...",
"delivery_time": double
}
APIs for user, attach user login JWT token when sending requests
POST $URL/cart: Add new product to cart / Modify quantity of an existing product / Delete a product in cart, quantity should not be delta(increment/decrement), it should be the final quantity. Set quantity to 0 to delete it.
{
'product_id': ...,
'quantity': 10
}
GET $URL/cart: Get product summary and quantity
{
"product_summary": {
...
},
"quantity": 2
}
POST $URL/userprofile: Update user profile settings, it will only change the first key-value pair. When updating address, whatever in the value will replace the original list
{
"email": ... OR
"password": ... OR
"address": [
"1",
"2",
"3"
] OR
"username": ...
}
POST $URL/order: Clear the current cart and create an order based on it
{
"address": ...,
"payment_method": ... (Not used in backend for now)
}
Authorization Token:
In *headers* section of the request, include a key of "Authorization", and a value of "Bearer <token>"
GET $URL/admin/empty: Get product summary of out-of-stock items, ADMIN TOKEN REQUIRED
{
product_summary1,
...
}
[!1]. not the full functionalities for now only search by keyword (not filter, or sort)
[!2]. no need to implement the show subcategory, as it can be displayed using the search