You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/backend-web-development/company-reviews-lab.md
+61-12Lines changed: 61 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
## Pokemon
1
+
## Company reviews
2
2
3
-
We will be building a React frontend with Express.js backend API for users giving reviews of companies data with Mongoose.
3
+
We will be building a Express.js backend API for users giving reviews of companies data with Mongoose. A React frontend can also be built to retrieve and store data to and from this backend API.
4
4
5
5
## Planning the CRUD API
6
6
@@ -20,7 +20,10 @@ Expected response:`
20
20
"1": "GET /companies",
21
21
"2": "GET /companies/:id",
22
22
"3": "POST /companies/:id/reviews",
23
-
"4": "GET /user"
23
+
"4": "GET /user",
24
+
"5": "POST /user/register",
25
+
"6": "POST /user/login",
26
+
"7": "POST /user/logout"
24
27
}
25
28
```
26
29
@@ -61,7 +64,7 @@ const companiesData = [
61
64
{
62
65
id:"7da4d967-715b-4dc1-a74b-82a7992704f3",
63
66
userId:"f6e016e6-e254-4375-bf82-797e6c00e3eb",
64
-
userName:"Brennan Fisher",
67
+
username:"brenfish",
65
68
rating:0,
66
69
title:"eligendi adipisci",
67
70
review:
@@ -70,7 +73,7 @@ const companiesData = [
70
73
{
71
74
id:"fa07ef47-5849-4642-8af0-640e4887b1e6",
72
75
userId:"13d0782f-2793-4c83-8279-93c9a03b3ac3",
73
-
userName:"Annalise Nicolas",
76
+
username:"annanico",
74
77
rating:4,
75
78
title:"iusto consequatur",
76
79
review:
@@ -103,15 +106,15 @@ Expected reponse:
103
106
{
104
107
"id":"7da4d967-715b-4dc1-a74b-82a7992704f3",
105
108
"userId":"f6e016e6-e254-4375-bf82-797e6c00e3eb",
106
-
"userName":"Brennan Fisher",
109
+
"username":"brenfish",
107
110
"rating":0,
108
111
"title":"eligendi adipisci",
109
112
"review":"Consequatur esse beatae voluptate voluptatibus expedita aperiam perspiciatis cumque voluptatem. Cum quasi dolor ut dignissimos illum magni eos. Et aspernatur illum commodi."
110
113
},
111
114
{
112
115
"id":"fa07ef47-5849-4642-8af0-640e4887b1e6",
113
116
"userId":"13d0782f-2793-4c83-8279-93c9a03b3ac3",
114
-
"userName":"Annalise Nicolas",
117
+
"username":"annanico",
115
118
"rating":4,
116
119
"title":"iusto consequatur",
117
120
"review":"Facere dicta delectus impedit sunt sed officia omnis. Officiis vel optio corrupti iure. Atque iusto nemo. Ut voluptas quaerat omnis quis impedit maiores nihil ipsam. Quod ea sed voluptates. Dolorem officia esse enim."
@@ -141,19 +144,18 @@ If you are logged in as:
141
144
```json
142
145
{
143
146
"userId": "754aece9-64bf-42ab-b91c-bb65e2db3a37",
144
-
"userName": "Humberto Bruen"
147
+
"username": "humburn"
145
148
}
146
149
```
147
150
148
151
Expected response:
149
-
You can also choose to respond with all reviews for the company, not just the new review.
150
152
151
153
New review:
152
154
153
155
```json
154
156
{
155
157
"userId": "754aece9-64bf-42ab-b91c-bb65e2db3a37",
156
-
"userName": "Humberto Bruen",
158
+
"username": "humburn",
157
159
"rating": 4,
158
160
"title": "eligendi adipisci",
159
161
"review": "Et voluptatem voluptas quisquam quos officia assumenda. Mollitia delectus vitae quia molestias nulla ut hic praesentium. Sed et assumenda et iusto velit laborum sunt non."
@@ -179,10 +181,58 @@ Expected response: (you get information about who you are logged in as)
179
181
"id": "754aece9-64bf-42ab-b91c-bb65e2db3a37",
180
182
"firstName": "Humberto",
181
183
"lastName": "Bruen",
184
+
"username": "humburn",
182
185
"email": "Timothy_VonRueden62@hotmail.com"
183
186
}
184
187
```
185
188
189
+
#### 5. POST /user/register to register
190
+
191
+
Route: POST /user/register
192
+
HTTP Response status code: 201
193
+
194
+
Sample request:
195
+
196
+
```json
197
+
{
198
+
"username": "aberkhoo",
199
+
"firstName": "Aber",
200
+
"lastName": "Khoo",
201
+
"password": "123456789",
202
+
"email": "Aber_Hoo@gmail.com",
203
+
};
204
+
```
205
+
206
+
Expected response:
207
+
208
+
```json
209
+
{
210
+
"id": "456abcd9-64bf-ab42-4c1f-ab4f23aa3a42",
211
+
"username": "aberkhoo",
212
+
"firstName": "Aber",
213
+
"lastName": "Khoo",
214
+
"password": "123456789",
215
+
"email": "Aber_Hoo@gmail.com"
216
+
}
217
+
```
218
+
219
+
#### 6. POST /user/login to login
220
+
221
+
Route: POST /user/login
222
+
223
+
HTTP Response status code: 200
224
+
225
+
Sample request:
226
+
227
+
```json
228
+
{
229
+
"username": "aberkhoo",
230
+
"password": "123456789",
231
+
};
232
+
```
233
+
234
+
#### 7. POST /user/logout to logout
235
+
186
236
Setup a new Github project and install Express.js, `git init`, `npm init -y`.
187
237
188
238
## Folder structure
@@ -217,6 +267,7 @@ Lab: Add basic routes, integrate Express routers to organise your routes
217
267
218
268
Lab: Integrate a default error handler middleware
219
269
Lab: Give 400 Bad Request response when doing POST request
0 commit comments