Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUBMIT BACK END - REST API + GRAPHIQL ~ By Prashant Wakchaure #6

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f95aa64
git push
prashant900555 Jan 31, 2019
f08bc3a
Commit preview
prashant900555 Jan 31, 2019
f32fd36
git commit -m asdasd
prashant900555 Jan 31, 2019
84a5f53
Merge branch 'master' of https://github.com/prashant900555/back-end-task
prashant900555 Jan 31, 2019
6c558fb
helloworld
prashant900555 Jan 31, 2019
bfbd776
Update README.md
prashant900555 Feb 4, 2019
b5700f8
Add files via upload
prashant900555 Feb 4, 2019
cc64c12
Add files via upload
prashant900555 Feb 4, 2019
b90c1dc
Update README.md
prashant900555 Feb 4, 2019
1e94d09
Update README.md
prashant900555 Feb 4, 2019
d7fc15c
Update README.md
prashant900555 Feb 4, 2019
4e94193
Update README.md
prashant900555 Feb 4, 2019
f78f53b
Update README.md
prashant900555 Feb 4, 2019
c9b430b
Update README.md
prashant900555 Feb 4, 2019
d064274
Update README.md
prashant900555 Feb 4, 2019
18d25fc
Update README.md
prashant900555 Feb 4, 2019
9d72d9a
Update README.md
prashant900555 Feb 9, 2019
c4b9578
Update README.md
prashant900555 Feb 9, 2019
614ef56
Update README.md
prashant900555 Feb 9, 2019
59940fb
Update README.md
prashant900555 Feb 9, 2019
449a6dd
Update README.md
prashant900555 Feb 9, 2019
0ae1e6b
Update README.md
prashant900555 Feb 9, 2019
c67405b
Set theme jekyll-theme-merlot
prashant900555 Feb 9, 2019
eff51ef
Delete _config.yml
prashant900555 Feb 9, 2019
d28430b
Update README.md
prashant900555 Feb 10, 2019
7596123
Update README.md
prashant900555 Feb 11, 2019
2f779cf
Update README.md
prashant900555 Feb 11, 2019
c249bc3
Update README.md
prashant900555 Feb 11, 2019
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
57 changes: 57 additions & 0 deletions API - Top 10 IMDB Movie List/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

# This is a plain API which uses nodejs, expressjs, mongoose(MongoDB) and Postman for GET,POST,PUT,DELETE query handling and execution.

<h4>
The database is a MongoDB database which has top 10 rated movies from imdb website. All the necessary node_modules such as 'mongoose', 'express', 'bodyParser' etc. are downloaded & installed through the bash cmd using GIT.
</h4>
The connection to mongodb takes place in "app.js"; wherein all the required node_modules are included.

mongoose.connect('mongodb://localhost/apiimdb', { useNewUrlParser: true });
"apiimdb" is the database which is created in MongoDB server.

In the models folder: The "movies.js" file contains the MovieSchema along with all the modules.export.queryfunctions;
The "movies.js" file is included in "app.js"; wherein, all the tasks are carried out.


/getAll - use http://localhost:3000/movies/getAll
req = GET , res = json(movies)

![add](https://user-images.githubusercontent.com/47216809/52517946-56be2180-2c69-11e9-8dd4-766eb32702ac.png)

/getAll (pagination) - use http://localhost:3000/movies/getAllPagination
req = GET , res = json(movies)
![add](https://github.com/prashant900555/back-end-task/blob/master/API%20-%20Top%2010%20IMDB%20Movie%20List/Screenshots/getAll%20(pagination).png?raw=true)

/getById - use http://localhost:3000/movies/getById/:_id
req = GET , res = json(movie)

![add](https://github.com/prashant900555/back-end-task/blob/master/API%20-%20Top%2010%20IMDB%20Movie%20List/Screenshots/getById.png?raw=true)

/search - use http://localhost:3000/movies/search/:genre
req = GET , res = json(movies)
(The string passed in the argument is genre)

![add](https://github.com/prashant900555/back-end-task/blob/master/API%20-%20Top%2010%20IMDB%20Movie%20List/Screenshots/search.png?raw=true)

/add - use http://localhost:3000/movies/add/
req = POST , res = json(movie)

![add](https://github.com/prashant900555/back-end-task/blob/master/API%20-%20Top%2010%20IMDB%20Movie%20List/Screenshots/add.png?raw=true)

/deleteById - use http://localhost:3000/movies/deleteById/:_id
req = DELETE , res = json(movie)

![add](https://github.com/prashant900555/back-end-task/blob/master/API%20-%20Top%2010%20IMDB%20Movie%20List/Screenshots/deleteById.png?raw=true)

/update - use http://localhost:3000/movies/movies/update/:_id
req = PUT , res = json(movie)

![add](https://github.com/prashant900555/back-end-task/blob/master/API%20-%20Top%2010%20IMDB%20Movie%20List/Screenshots/update.png?raw=true)

Please check the Screenshots folder for the queries and the execution in detail. Postman is used for the query handling and execution of the HTTP links given above.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\THANK - YOU///////////////////////////////////////////////////////////////////

PROJECT CREATED BY - Prashant Wakchaure
Email ID - [email protected]
Contact No. - 8975366296
Binary file added API - Top 10 IMDB Movie List/Screenshots/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions API - Top 10 IMDB Movie List/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');

// importing movies.js file
Movie = require('./models/movies');

app.use(bodyParser.json());

//Connection to mongoose
mongoose.connect('mongodb://localhost/apiimdb', { useNewUrlParser: true });
var db = mongoose.connection;

// /getAll
app.get('/movies/getAll', function(req, res){
Movie.getAllMovies(function(err, movies){
if(err){
throw err;
}
res.json(movies);
});
});

// /getAll (pagination)
app.get('/movies/getAllPagination', function(req, res){
Movie.getAllMoviesUsingPagination(function(err, movies){
if(err){
throw err;
}
res.json(movies);
});
});

// /getById
app.get('/movies/getById/:_id', function(req, res){
Movie.getMoviesById(req.params._id, function(err, movie){
if(err){
throw err;
}
res.json(movie);
});
});

// /search
app.get('/movies/search/:genre', function(req, res){
Movie.getMoviesByString(req.params.genre, function(err, movies){
if(err){
throw err;
}
res.json(movies);
});
});

// /add
app.post('/movies/add/', function(req, res){
var movie = req.body;
Movie.addMovies(movie, function(err, movie){
if(err){
throw err;
}
res.json(movie);
});
});

// /update
app.put('/movies/update/:_id', function(req, res){
var id = req.params._id;
var movie = req.body;
Movie.updateMovies(id, movie,{}, function(err, movie){
if(err){
throw err;
}
res.json(movie);
});
});

// /deleteById
app.delete('/movies/deleteById/:_id', function(req, res){
var id = req.params._id;
Movie.deleteMovies(id, function(err, movie){
if(err){
throw err;
}
res.json(movie);
});
});


app.listen(3000);
console.log('Running on port 3000...');
77 changes: 77 additions & 0 deletions API - Top 10 IMDB Movie List/models/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var mongoose = require('mongoose');

//Movies Schema
var movieSchema = mongoose.Schema({
movie:{
type: String,
required:true
},
genre:{
type: Object,
required:true
},
duration:{
type: String,
required:true
},
date_of_release:{
type: String,
required:true
},
director:{
type: String,
required:true
},
trailer_link:{
type: String,
required:true
},
imdb_rating:{
type: Number,
required:true
},
imdb_rank:{
type: Number,
required:true
}
});

var Movie = module.exports = mongoose.model('Movie', movieSchema);

// /getAll
module.exports.getAllMovies = function(callback, limit){
Movie.find(callback).limit(limit);
}

// /getAll(pagination)
module.exports.getAllMoviesUsingPagination = function(callback, limit){
Movie.find(callback).limit(6);
}

// /getById
module.exports.getMoviesById = function(id, callback){
Movie.findById(id, callback);
}

// /search
module.exports.getMoviesByString = function(genre, callback) {
var query = { genre: genre};
Movie.find(query, callback);
}

// /add
module.exports.addMovies = function(movie, callback){
Movie.create(movie, callback);
}

// /update
module.exports.updateMovies = function(id, movie, options, callback){
var query = {_id: id};
Movie.findOneAndUpdate(query,{$set: movie},{upsert:true, new:true}, callback);
}

// /deleteById
module.exports.deleteMovies = function(id, callback){
var query = {_id: id};
Movie.remove(query, callback);
}
Loading