v2 endpoints added for clearer intent in endpoints. Two new controller categories; info and search.
This commit is contained in:
@@ -68,6 +68,17 @@ class TMDB {
|
|||||||
.then(response => this.mapResults(response));
|
.then(response => this.mapResults(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
multiSearch(search_query, page=1) {
|
||||||
|
const query = { query: search_query, page: page };
|
||||||
|
const cacheKey = `${this.cacheTags.multiSeach}:${page}:${search_query}`;
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => this.cache.get(cacheKey))
|
||||||
|
.catch(() => this.tmdb('searchMulti', query))
|
||||||
|
.catch(() => { throw new Error('Could not complete search to tmdb'); })
|
||||||
|
.then(response => this.cache.set(cacheKey, response))
|
||||||
|
.then(response => this.mapResults(response));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a given list from tmdb.
|
* Fetches a given list from tmdb.
|
||||||
* @param {String} listName Name of list
|
* @param {String} listName Name of list
|
||||||
@@ -122,7 +133,7 @@ class TMDB {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return reject(error);
|
return reject(error);
|
||||||
}
|
}
|
||||||
return resolve(reponse);
|
resolve(reponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!argument) {
|
if (!argument) {
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ router.get('/v1/seasoned/all', require('./controllers/seasoned/readStrays.js'));
|
|||||||
router.get('/v1/seasoned/:strayId', require('./controllers/seasoned/strayById.js'));
|
router.get('/v1/seasoned/:strayId', require('./controllers/seasoned/strayById.js'));
|
||||||
router.post('/v1/seasoned/verify/:strayId', require('./controllers/seasoned/verifyStray.js'));
|
router.post('/v1/seasoned/verify/:strayId', require('./controllers/seasoned/verifyStray.js'));
|
||||||
|
|
||||||
|
router.get('/v2/search/', require('./controllers/search/multiSearch.js'));
|
||||||
|
router.get('/v2/search/movie', require('./controllers/search/movieSearch.js'));
|
||||||
|
router.get('/v2/search/show', require('./controllers/search/showSearch.js'));
|
||||||
|
router.get('/v2/search/person', require('./controllers/search/personSearch.js'));
|
||||||
|
|
||||||
|
router.get('/v2/movie/:id', require('./controllers/info/movieInfo.js'));
|
||||||
|
router.get('/v2/show/:id', require('./controllers/info/showInfo.js'));
|
||||||
|
router.get('/v2/person/:id', require('./controllers/info/personInfo.js'));
|
||||||
/**
|
/**
|
||||||
* Plex
|
* Plex
|
||||||
*/
|
*/
|
||||||
|
|||||||
24
seasoned_api/src/webserver/controllers/info/movieInfo.js
Normal file
24
seasoned_api/src/webserver/controllers/info/movieInfo.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Retrieve information for a movie
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
|
||||||
|
function movieInfoController(req, res) {
|
||||||
|
const movieId = req.params.id;
|
||||||
|
tmdb.movieInfo(movieId)
|
||||||
|
.then((movie) => {
|
||||||
|
res.send(movie);
|
||||||
|
}).catch((error) => {
|
||||||
|
res.status(404).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = movieInfoController;
|
||||||
24
seasoned_api/src/webserver/controllers/info/personInfo.js
Normal file
24
seasoned_api/src/webserver/controllers/info/personInfo.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Retrieve information for a person
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
|
||||||
|
function personInfoController(req, res) {
|
||||||
|
const personId = req.params.id;
|
||||||
|
tmdb.personInfo(personId)
|
||||||
|
.then((person) => {
|
||||||
|
res.send(person);
|
||||||
|
}).catch((error) => {
|
||||||
|
res.status(404).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = personInfoController;
|
||||||
24
seasoned_api/src/webserver/controllers/info/showInfo.js
Normal file
24
seasoned_api/src/webserver/controllers/info/showInfo.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Retrieve information for a show
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
|
||||||
|
function showInfoController(req, res) {
|
||||||
|
const showId = req.params.id;
|
||||||
|
tmdb.showInfo(showId)
|
||||||
|
.then((show) => {
|
||||||
|
res.send(show);
|
||||||
|
}).catch((error) => {
|
||||||
|
res.status(404).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = showInfoController;
|
||||||
35
seasoned_api/src/webserver/controllers/search/movieSearch.js
Normal file
35
seasoned_api/src/webserver/controllers/search/movieSearch.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const SearchHistory = require('src/searchHistory/searchHistory');
|
||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
const searchHistory = new SearchHistory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Search for movies by query and pagey
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
function movieSearchController(req, res) {
|
||||||
|
const user = req.loggedInUser;
|
||||||
|
const { query, page } = req.query;
|
||||||
|
|
||||||
|
Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
if (user) {
|
||||||
|
return searchHistory.create(user, query);
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
.then(() => tmdb.movieSearch(query, page))
|
||||||
|
.then((movies) => {
|
||||||
|
res.send(movies);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
res.status(500).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = movieSearchController;
|
||||||
35
seasoned_api/src/webserver/controllers/search/multiSearch.js
Normal file
35
seasoned_api/src/webserver/controllers/search/multiSearch.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const SearchHistory = require('src/searchHistory/searchHistory');
|
||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
const searchHistory = new SearchHistory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Search for multi (movies, shows and people by query and pagey
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
function multiSearchController(req, res) {
|
||||||
|
const user = req.loggedInUser;
|
||||||
|
const { query, page } = req.query;
|
||||||
|
|
||||||
|
Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
if (user) {
|
||||||
|
return searchHistory.create(user, query);
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
.then(() => tmdb.multiSearch(query, page))
|
||||||
|
.then((result) => {
|
||||||
|
res.send(result);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
res.status(500).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = multiSearchController;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
const SearchHistory = require('src/searchHistory/searchHistory');
|
||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
const searchHistory = new SearchHistory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Search for person by query and pagey
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
function personSearchController(req, res) {
|
||||||
|
const user = req.loggedInUser;
|
||||||
|
const { query, page } = req.query;
|
||||||
|
|
||||||
|
Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
if (user) {
|
||||||
|
return searchHistory.create(user, query);
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
.then(() => tmdb.personSearch(query, page))
|
||||||
|
.then((person) => {
|
||||||
|
res.send(person);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
res.status(500).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = personSearchController;
|
||||||
35
seasoned_api/src/webserver/controllers/search/showSearch.js
Normal file
35
seasoned_api/src/webserver/controllers/search/showSearch.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const SearchHistory = require('src/searchHistory/searchHistory');
|
||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
const searchHistory = new SearchHistory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller: Search for shows by query and pagey
|
||||||
|
* @param {Request} req http request variable
|
||||||
|
* @param {Response} res
|
||||||
|
* @returns {Callback}
|
||||||
|
*/
|
||||||
|
function showSearchController(req, res) {
|
||||||
|
const user = req.loggedInUser;
|
||||||
|
const { query, page } = req.query;
|
||||||
|
|
||||||
|
Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
if (user) {
|
||||||
|
return searchHistory.create(user, query);
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
.then(() => tmdb.showSearch(query, page))
|
||||||
|
.then((shows) => {
|
||||||
|
res.send(shows);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
res.status(500).send({ success: false, error: error.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = showSearchController;
|
||||||
Reference in New Issue
Block a user