diff --git a/Readme.md b/Readme.md index 6fcfbef..8145f7f 100644 --- a/Readme.md +++ b/Readme.md @@ -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 ## Tutorial You can find the tutorial for this application at [The CalliCoder Blog](https://www.callicoder.com) - - \ No newline at end of file + diff --git a/app/controllers/note.controller.js b/app/controllers/note.controller.js index 7390849..85bd86a 100644 --- a/app/controllers/note.controller.js +++ b/app/controllers/note.controller.js @@ -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 @@ -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) { diff --git a/app/models/note.model.js b/app/models/note.model.js index d5523c6..f335113 100644 --- a/app/models/note.model.js +++ b/app/models/note.model.js @@ -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); \ No newline at end of file +module.exports = mongoose.model('Note', NoteSchema); diff --git a/app/routes/note.routes.js b/app/routes/note.routes.js index 52809a8..f0a2dad 100644 --- a/app/routes/note.routes.js +++ b/app/routes/note.routes.js @@ -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); @@ -15,4 +17,4 @@ module.exports = (app) => { // Delete a Note with noteId app.delete('/notes/:noteId', notes.delete); -} \ No newline at end of file +}