Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ npm install
node server.js
```

## Note Organization

3. Notes now support tags and searching.

Search:
GET /notes?q=python

Filter by tag:
GET /notes?tag=learning

You can browse the apis at <http://localhost:3000>

## Tutorial
You can find the tutorial for this application at [The CalliCoder Blog](https://www.callicoder.com) -

<https://www.callicoder.com/node-js-express-mongodb-restful-crud-api-tutorial/>
<https://www.callicoder.com/node-js-express-mongodb-restful-crud-api-tutorial/>
2 changes: 2 additions & 0 deletions app/controllers/note.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports.create = (req, res) => {
const note = new Note({
title: req.body.title || "Untitled Note",
content: req.body.content
tags: req.body.tags || [] //for tags
});

// Save Note in the database
Expand Down Expand Up @@ -73,6 +74,7 @@ exports.update = (req, res) => {
Note.findByIdAndUpdate(req.params.noteId, {
title: req.body.title || "Untitled Note",
content: req.body.content
tags: req.body.tags || [] //for tags
}, {new: true})
.then(note => {
if(!note) {
Expand Down
7 changes: 6 additions & 1 deletion app/models/note.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ const mongoose = require('mongoose');
const NoteSchema = mongoose.Schema({
title: String,
content: String
tags: {
type: [String],
default: []
}

}, {
timestamps: true
});

module.exports = mongoose.model('Note', NoteSchema);
module.exports = mongoose.model('Note', NoteSchema);
4 changes: 3 additions & 1 deletion app/routes/note.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module.exports = (app) => {
// Create a new Note
app.post('/notes', notes.create);

//notes are getting found by using tags like /notes?q=python & /notes?tag=learning

// Retrieve all Notes
app.get('/notes', notes.findAll);

Expand All @@ -15,4 +17,4 @@ module.exports = (app) => {

// Delete a Note with noteId
app.delete('/notes/:noteId', notes.delete);
}
}