Skip to content

Commit f8a28e1

Browse files
[mabel] Edit and rename company review labs
1 parent 3554825 commit f8a28e1

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
- [Express.js Mongoose lab](backend-web-development/express-mongoose-lab)
127127
- [Express.js to production](backend-web-development/express-to-production)
128128
- [Express.js deploy](backend-web-development/express-deploy)
129-
- [Express.js Mongoose frontend lab](backend-web-development/express-mongoose-with-frontend-lab)
129+
- [Company reviews lab](backend-web-development/company-reviews-lab)
130130
- [Labs for backend](backend-web-development/backend-labs)
131131

132132
- **Delivering software**

docs/backend-web-development/express-mongoose-with-frontend-lab.md renamed to docs/backend-web-development/company-reviews-lab.md

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Pokemon
1+
## Company reviews
22

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.
44

55
## Planning the CRUD API
66

@@ -20,7 +20,10 @@ Expected response:`
2020
"1": "GET /companies",
2121
"2": "GET /companies/:id",
2222
"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"
2427
}
2528
```
2629

@@ -61,7 +64,7 @@ const companiesData = [
6164
{
6265
id: "7da4d967-715b-4dc1-a74b-82a7992704f3",
6366
userId: "f6e016e6-e254-4375-bf82-797e6c00e3eb",
64-
userName: "Brennan Fisher",
67+
username: "brenfish",
6568
rating: 0,
6669
title: "eligendi adipisci",
6770
review:
@@ -70,7 +73,7 @@ const companiesData = [
7073
{
7174
id: "fa07ef47-5849-4642-8af0-640e4887b1e6",
7275
userId: "13d0782f-2793-4c83-8279-93c9a03b3ac3",
73-
userName: "Annalise Nicolas",
76+
username: "annanico",
7477
rating: 4,
7578
title: "iusto consequatur",
7679
review:
@@ -103,15 +106,15 @@ Expected reponse:
103106
{
104107
"id":"7da4d967-715b-4dc1-a74b-82a7992704f3",
105108
"userId":"f6e016e6-e254-4375-bf82-797e6c00e3eb",
106-
"userName":"Brennan Fisher",
109+
"username":"brenfish",
107110
"rating":0,
108111
"title":"eligendi adipisci",
109112
"review":"Consequatur esse beatae voluptate voluptatibus expedita aperiam perspiciatis cumque voluptatem. Cum quasi dolor ut dignissimos illum magni eos. Et aspernatur illum commodi."
110113
},
111114
{
112115
"id":"fa07ef47-5849-4642-8af0-640e4887b1e6",
113116
"userId":"13d0782f-2793-4c83-8279-93c9a03b3ac3",
114-
"userName":"Annalise Nicolas",
117+
"username":"annanico",
115118
"rating":4,
116119
"title":"iusto consequatur",
117120
"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:
141144
```json
142145
{
143146
"userId": "754aece9-64bf-42ab-b91c-bb65e2db3a37",
144-
"userName": "Humberto Bruen"
147+
"username": "humburn"
145148
}
146149
```
147150

148151
Expected response:
149-
You can also choose to respond with all reviews for the company, not just the new review.
150152

151153
New review:
152154

153155
```json
154156
{
155157
"userId": "754aece9-64bf-42ab-b91c-bb65e2db3a37",
156-
"userName": "Humberto Bruen",
158+
"username": "humburn",
157159
"rating": 4,
158160
"title": "eligendi adipisci",
159161
"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)
179181
"id": "754aece9-64bf-42ab-b91c-bb65e2db3a37",
180182
"firstName": "Humberto",
181183
"lastName": "Bruen",
184+
"username": "humburn",
182185
"email": "Timothy_VonRueden62@hotmail.com"
183186
}
184187
```
185188

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+
186236
Setup a new Github project and install Express.js, `git init`, `npm init -y`.
187237

188238
## Folder structure
@@ -217,6 +267,7 @@ Lab: Add basic routes, integrate Express routers to organise your routes
217267

218268
Lab: Integrate a default error handler middleware
219269
Lab: Give 400 Bad Request response when doing POST request
270+
Lab: Add Joi Validation and 400 errors
220271

221272
## Mongo and Mongoose
222273

@@ -228,8 +279,6 @@ const dbUrl = process.env.MONGODB_URI || "mongodb://localhost:27017/" + dbName;
228279

229280
### Create schema, validate, create model
230281

231-
How do we get the userName of a user with only firstName and lastName?
232-
233282
## Add authentication to protect routes
234283

235284
jsonwebtoken

0 commit comments

Comments
 (0)