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

load movies/series details from an external api #55

Merged
merged 4 commits into from
Oct 8, 2018
Merged
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
6 changes: 6 additions & 0 deletions back-end/controllers/series_movie_controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require('mongoose');
const Series = require('../models').Series;
const Movies = require('../models').Movie;
var TVMazeService = require('../services/tvmaze.service');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a const?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this could be a const, but that's not a deal breaker.


module.exports = {
series(req, res) {
Expand Down Expand Up @@ -80,5 +81,10 @@ module.exports = {
res.send(series.episodes.id(episodeId));
}
})
},

loadAdditionalSeriesDetails(req, res) {
var showName = req.params.name;
TVMazeService.loadDataByName(showName).then((data) => res.send(data));
}
}
9 changes: 7 additions & 2 deletions back-end/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion back-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"license": "MIT",
"dependencies": {
"express": "^4.16.3",
"mongoose": "^5.3.1"
"mongoose": "^5.3.1",
"node-fetch": "^2.2.0"
},
"devDependencies": {
"reload": "^2.3.1"
Expand Down
1 change: 1 addition & 0 deletions back-end/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function initRoutes(app) {
app.get('/series/:id/episodes/:eid', SeriesMovieController.episodesByEid);
app.get('/movies', SeriesMovieController.movies);
app.get('/movies/:id', SeriesMovieController.moviesById);
app.get('/search/:name', SeriesMovieController.loadAdditionalSeriesDetails);
}

module.exports = initRoutes;
13 changes: 13 additions & 0 deletions back-end/services/tvmaze.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fetch = require('node-fetch');

var TVMazeService = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also out of curiousity, why not use let?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be a constant, since it doesn't get modified. In the beginning, I tried to keep it ES5 only, but looking at the project currently, it already is a mix between var and const/let maybe someone will go through it in the future and update them.

loadDataByName: loadDataByName
}

function loadDataByName(showName) {
return fetch("http://api.tvmaze.com/search/shows?q="+ showName)
.then((response) => response.json())
.catch((err) => console.error(err))
}

module.exports = TVMazeService;
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.