Skip to content

Commit 64e8ab7

Browse files
committed
add status codes, id to reqs
also remove model schema diff
1 parent 368a9a7 commit 64e8ab7

File tree

3 files changed

+7
-12
lines changed
  • module3-crud-and-data-models

3 files changed

+7
-12
lines changed

module3-crud-and-data-models/r1-schema-and-data-models/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ CREATE TABLE customer (
3333

3434
We can see that the schema definition for the `customer` has a `name` which is a type `string` and a `zipcode` that is of type `number`.
3535

36-
### The Difference between data model and schema
37-
38-
The database schema is one that contains list of attributes and instructions to tell the database engine how data is organised whereas data model is a collection of conceptional tools for describing data, data-relationship and consistency constraints.
39-
4036
## Introduction to CRUD operations
4137

4238
When we are building APIs, we want our models to provide four basic types of functionality. The model must be able to Create, Read, Update, and Delete resources. Computer scientists often refer to these functions by the acronym `CRUD`. A model should have the ability to perform at most these four functions in order to be complete.
@@ -85,16 +81,16 @@ Note: Use `PUT` when you want to modify a singular resource which is already a p
8581

8682
##### Request:
8783

88-
`PUT http://www.myrestaurant.com/dishes/1223`
84+
`PUT http://www.myrestaurant.com/dishes/:id`
8985

9086
#### Delete
9187

9288
The CRUD operation Delete corresponds to the HTTP method DELETE. It is used to remove a resource from the system.
93-
Let’s say that the world avocado shortage has reached a critical point, and we can no longer afford to serve this modern delicacy at all. We should go into the database and delete the item that corresponds to `"Avocado Toast"`, which we know has an `id` of 1223.
89+
Let’s say that the world avocado shortage has reached a critical point, and we can no longer afford to serve this modern delicacy at all. We should go into the database and delete the item that corresponds to `Avocado Toast`, which we know has an `id` of 1223.
9490

9591
##### Request:
9692

97-
`DELETE http://www.myrestaurant.com/dishes/1223`
93+
`DELETE http://www.myrestaurant.com/dishes/:id`
9894

9995
## Resources
10096

module3-crud-and-data-models/r1.1-principles-of-setting-up-your-schema/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ Most developers don't see the difference between relational database schema and
1010

1111
<img src="https://i.imgur.com/3yobiPB.jpg" alt="meme" width="400"/>
1212

13-
In a nutshell,
14-
in relational databases, models are usually independent of queries, there is no duplication of data as data will _mostly_ be separated into different tables, and it is rigid, you will have to define types and fields for your schema beforehand.
13+
In a nutshell, in relational databases, models are usually independent of queries, there is no duplication of data as data will _mostly_ be separated into different tables, and it is rigid, you will have to define types and fields for your schema beforehand.
1514

1615
in the other hand, `MongoDB`, you have more flexibility, there are no rules, documents can have new data or fields at any point of time, no need to define types.
1716

module3-crud-and-data-models/r3.2-models-and-controllers-in-mongoose/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Example:
6666
app.post("/food", async (request, response) => {
6767
const food = new foodModel(request.body);
6868
await food.save();
69-
response.send(food);
69+
response.status(201).send(food);
7070
});
7171

7272
// ...
@@ -81,7 +81,7 @@ Example:
8181
```js
8282
// ...
8383

84-
app.patch("/food/:id", async (request, response) => {
84+
app.put("/food/:id", async (request, response) => {
8585
await foodModel.findByIdAndUpdate(request.params.id, request.body);
8686
await foodModel.save();
8787
response.send(food);
@@ -104,7 +104,7 @@ app.delete("/food/:id", async (request, response) => {
104104
const food = await foodModel.findByIdAndDelete(request.params.id);
105105

106106
if (!food) response.status(404).send("No item found");
107-
response.status(200).send();
107+
response.status(204).send();
108108
}
109109
});
110110

0 commit comments

Comments
 (0)