Skip to content

Commit 603252d

Browse files
committed
all get api's created
1 parent 5a12e6d commit 603252d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CRUD API's/app/controllers/controller.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,41 @@ exports.findAll=function(req,res){
3535
// find a note by id
3636
exports.findone=function(req,res){
3737

38+
Note.findById(req.params.noteId)
39+
.then(note=>{
40+
if(!note){
41+
return res.status(400).send({message:"Note not found with id " + req.params.noteId});
42+
}
43+
res.status(200).send(note);
44+
}).catch(err=>{
45+
if(err.kind=='ObjectId'){
46+
return res.status(404).send({ message: "Note not found with id " + req.params.noteId });
47+
}
48+
return res.status(500).send({
49+
message: "Error retrieving note with id " + req.params.noteId
50+
});
51+
});
52+
53+
};
3854

55+
//request to find ny the name of author
56+
exports.findbyauthor=function(req,res){
57+
Note.find({author:req.params.author},function(err,note){
58+
if(note) return res.status(400).send(note);
59+
60+
res.status(400).send({message : "No author with given name has been found"});
61+
62+
});
63+
};
64+
65+
// request to find by the name of title of note
66+
exports.findbytitle=function(req,res){
67+
Note.find({title:req.params.title},function(err,note){
68+
if(note) return res.status(400).send(note);
69+
70+
res.status(400).send({message : "No author with given name has been found"});
71+
72+
});
3973
};
4074

4175
exports.update=function(req,res){

CRUD API's/app/routes/routes.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ module.exports=(app)=>{
88
app.get('/api/notes',notes.findAll);
99

1010
//retrive a single note by id
11-
app.get('/api/notes/:noteId',notes.findone);
11+
app.get('/api/find/:noteId',notes.findone);
12+
13+
//retrive all notes by a particular author
14+
app.get('/api/findauthor/:author',notes.findbyauthor);
15+
16+
// retrive all notes by the note title
17+
app.get('/api/findbytitle/:title',notes.findbytitle);
1218

1319
//update a note with noteId
1420
app.put('/api/notes/:noteId',notes.update);

0 commit comments

Comments
 (0)