Skip to content

Commit

Permalink
Zee: Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zee committed Feb 28, 2016
1 parent 9419919 commit 4cb103c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 94 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "FamilyFriendly",
"name": "family-friendly-api",
"version": "0.0.1",
"private": true,
"scripts": {
Expand Down
178 changes: 85 additions & 93 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,92 @@ const express = require('express'),
log = require('../logger'),
movieDbService = require('../helpers/moviedb-helper');

router.get('/', function(req, res) {
res.sendStatus(200);
});

router.get('/search/:moviename', function(req, res) {

movieDbService.getMoviesFromSearch(req.params.moviename, req)
.then(movies => {
res.json(movies);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occurred trying to retrieve movies');
});
});

router.get('/movie/:movieid', function(req, res) {
movieDbService.getMovieById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie information by its id');
});
});

router.get('/movie/:movieid/credits', function(req, res) {
movieDbService.getMovieCreditsById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie credits by its id');
});
});

router.get('/movie/:movieid/images', function(req, res) {
movieDbService.getMovieImagesById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie images by its id');
});
});
router
.get('/', function(req, res) {
res.sendStatus(200);
})
.get('/search/:moviename', function(req, res) {

router.get('/movie/:movieid/videos', function(req, res) {
movieDbService.getMovieVideosById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie videos by its id');
});
});

router.get('/movie/:movieid/trailers', function(req, res) {
movieDbService.getMovieTrailerById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie trailers by its id');
});
});

router.get('/movie/:movieid/keywords', function(req, res) {
movieDbService.getMovieKeywordsById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie keywords by its id');
});
});

router.get('/movie/:movieid/similar', function(req, res) {
movieDbService.getSimilarMoviesById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the similar movies by its id');
});
});

router.get('/latestmovies', function(req, res) {
movieDbService.getLatestMovies(req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the latest movies');
});
});
movieDbService.getMoviesFromSearch(req.params.moviename, req)
.then(movies => {
res.json(movies);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occurred trying to retrieve movies');
});
})
.get('/movie/:movieid', function(req, res) {
movieDbService.getMovieById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie information by its id');
});
})
.get('/movie/:movieid/credits', function(req, res) {
movieDbService.getMovieCreditsById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie credits by its id');
});
})
.get('/movie/:movieid/images', function(req, res) {
movieDbService.getMovieImagesById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie images by its id');
});
})
.get('/movie/:movieid/videos', function(req, res) {
movieDbService.getMovieVideosById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie videos by its id');
});
})
.get('/movie/:movieid/trailers', function(req, res) {
movieDbService.getMovieTrailerById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie trailers by its id');
});
})
.get('/movie/:movieid/keywords', function(req, res) {
movieDbService.getMovieKeywordsById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie keywords by its id');
});
})
.get('/movie/:movieid/similar', function(req, res) {
movieDbService.getSimilarMoviesById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the similar movies by its id');
});
})
.get('/latestmovies', function(req, res) {
movieDbService.getLatestMovies(req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the latest movies');
});
});

// TODO: implement versioning and output
router.get('/version', function(req, res) {
Expand Down

0 comments on commit 4cb103c

Please sign in to comment.