diff --git a/back-end/controllers/series_movie_controller.js b/back-end/controllers/series_movie_controller.js index 85ae3ab..27ff8d2 100644 --- a/back-end/controllers/series_movie_controller.js +++ b/back-end/controllers/series_movie_controller.js @@ -1,6 +1,7 @@ const mongoose = require('mongoose'); const Series = require('../models').Series; const Movies = require('../models').Movie; +var TVMazeService = require('../services/tvmaze.service'); module.exports = { series(req, res) { @@ -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)); } } diff --git a/back-end/package-lock.json b/back-end/package-lock.json index e0a6ab6..751328b 100644 --- a/back-end/package-lock.json +++ b/back-end/package-lock.json @@ -86,7 +86,7 @@ }, "commander": { "version": "2.9.0", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.9.0.tgz", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", "dev": true, "requires": { @@ -400,7 +400,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, @@ -523,6 +523,11 @@ "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", "dev": true }, + "node-fetch": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.2.0.tgz", + "integrity": "sha512-OayFWziIxiHY8bCUyLX6sTpDH8Jsbp4FfYd1j1f7vZyfgkcOnAyM4oQR16f8a0s7Gl/viMGRey8eScYk4V4EZA==" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", diff --git a/back-end/package.json b/back-end/package.json index 3246ac1..b7ab1cb 100644 --- a/back-end/package.json +++ b/back-end/package.json @@ -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" diff --git a/back-end/routes.js b/back-end/routes.js index 0c5721b..6f3a31f 100644 --- a/back-end/routes.js +++ b/back-end/routes.js @@ -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; diff --git a/back-end/services/tvmaze.service.js b/back-end/services/tvmaze.service.js new file mode 100644 index 0000000..299d37d --- /dev/null +++ b/back-end/services/tvmaze.service.js @@ -0,0 +1,13 @@ +const fetch = require('node-fetch'); + +var TVMazeService = { + 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; diff --git a/package-lock.json b/package-lock.json index 2e9bafc..c81617d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -473,7 +473,7 @@ }, "duplexer": { "version": "0.1.1", - "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", + "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", "dev": true }, @@ -1297,7 +1297,7 @@ }, "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", "dev": true }, @@ -1339,7 +1339,7 @@ }, "got": { "version": "6.7.1", - "resolved": "http://registry.npmjs.org/got/-/got-6.7.1.tgz", + "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", "integrity": "sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=", "dev": true, "requires": { @@ -1578,7 +1578,7 @@ }, "is-obj": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", "dev": true }, @@ -1741,7 +1741,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, @@ -1942,7 +1942,7 @@ }, "pause-stream": { "version": "0.0.11", - "resolved": "http://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", + "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", "integrity": "sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=", "dev": true, "requires": { @@ -2418,7 +2418,7 @@ }, "through": { "version": "2.3.8", - "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true },