Read and pass adult search query param consistently for movie, show & person info
This commit is contained in:
@@ -176,13 +176,13 @@ class TMDB {
|
|||||||
* @param {Number} page representing pagination of results
|
* @param {Number} page representing pagination of results
|
||||||
* @returns {Promise} dict with query results, current page and total_pages
|
* @returns {Promise} dict with query results, current page and total_pages
|
||||||
*/
|
*/
|
||||||
movieSearch(query, page=1, adult=true) {
|
movieSearch(search_query, page = 1, include_adult = true) {
|
||||||
const tmdbquery = { query: query, page: page, adult: adult };
|
const tmdbquery = { query: search_query, page, include_adult };
|
||||||
const cacheKey = `tmdb/${this.cacheTags.movieSearch}:${page}:${query}:${adult}`;
|
const cacheKey = `tmdb/${this.cacheTags.movieSearch}:${page}:${search_query}:${include_adult}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMovie', query)
|
return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchMovie", tmdbquery)
|
||||||
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
||||||
.then(response => this.mapResults(response, 'movie'))
|
.then(response => this.mapResults(response, "movie"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,13 +191,13 @@ class TMDB {
|
|||||||
* @param {Number} page representing pagination of results
|
* @param {Number} page representing pagination of results
|
||||||
* @returns {Promise} dict with query results, current page and total_pages
|
* @returns {Promise} dict with query results, current page and total_pages
|
||||||
*/
|
*/
|
||||||
showSearch(query, page=1) {
|
showSearch(search_query, page = 1, include_adult = true) {
|
||||||
const tmdbquery = { query: query, page: page };
|
const tmdbquery = { query: search_query, page, include_adult };
|
||||||
const cacheKey = `tmdb/${this.cacheTags.showSearch}:${page}:${query}`;
|
const cacheKey = `tmdb/${this.cacheTags.showSearch}:${page}:${search_query}:${include_adult}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchTv', query)
|
return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchTv", tmdbquery)
|
||||||
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
||||||
.then(response => this.mapResults(response, 'show'))
|
.then(response => this.mapResults(response, "show"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,14 +206,13 @@ class TMDB {
|
|||||||
* @param {Number} page representing pagination of results
|
* @param {Number} page representing pagination of results
|
||||||
* @returns {Promise} dict with query results, current page and total_pages
|
* @returns {Promise} dict with query results, current page and total_pages
|
||||||
*/
|
*/
|
||||||
personSearch(query, page=1) {
|
personSearch(search_query, page = 1, include_adult = true) {
|
||||||
|
const tmdbquery = { query: search_query, page, include_adult };
|
||||||
|
const cacheKey = `tmdb/${this.cacheTags.personSearch}:${page}:${search_query}:${include_adult}`;
|
||||||
|
|
||||||
const tmdbquery = { query: query, page: page, include_adult: true };
|
return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchPerson", tmdbquery)
|
||||||
const cacheKey = `tmdb/${this.cacheTags.personSearch}:${page}:${query}:${include_adult}`;
|
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchPerson', query)
|
|
||||||
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
||||||
.then(response => this.mapResults(response, 'person'))
|
.then(response => this.mapResults(response, "person"));
|
||||||
}
|
}
|
||||||
|
|
||||||
movieList(listname, page = 1) {
|
movieList(listname, page = 1) {
|
||||||
|
|||||||
@@ -11,15 +11,16 @@ const searchHistory = new SearchHistory();
|
|||||||
* @returns {Callback}
|
* @returns {Callback}
|
||||||
*/
|
*/
|
||||||
function movieSearchController(req, res) {
|
function movieSearchController(req, res) {
|
||||||
const { query, page } = req.query;
|
const { query, page, adult } = req.query;
|
||||||
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
||||||
|
const includeAdult = adult == "true" ? true : false;
|
||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
return searchHistory.create(username, query);
|
searchHistory.create(username, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmdb
|
return tmdb
|
||||||
.movieSearch(query, page)
|
.movieSearch(query, page, includeAdult)
|
||||||
.then(movieSearchResults => res.send(movieSearchResults))
|
.then(movieSearchResults => res.send(movieSearchResults))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const { status, message } = error;
|
const { status, message } = error;
|
||||||
|
|||||||
@@ -11,18 +11,17 @@ const searchHistory = new SearchHistory();
|
|||||||
* @returns {Callback}
|
* @returns {Callback}
|
||||||
*/
|
*/
|
||||||
function personSearchController(req, res) {
|
function personSearchController(req, res) {
|
||||||
const { query, page } = req.query;
|
const { query, page, adult } = req.query;
|
||||||
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
||||||
|
const includeAdult = adult == "true" ? true : false;
|
||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
return searchHistory.create(username, query);
|
searchHistory.create(username, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmdb
|
return tmdb
|
||||||
.personSearch(query, page)
|
.personSearch(query, page, includeAdult)
|
||||||
.then(person => {
|
.then(persons => res.send(persons))
|
||||||
res.send(person);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const { status, message } = error;
|
const { status, message } = error;
|
||||||
|
|
||||||
|
|||||||
@@ -11,17 +11,16 @@ const searchHistory = new SearchHistory();
|
|||||||
* @returns {Callback}
|
* @returns {Callback}
|
||||||
*/
|
*/
|
||||||
function showSearchController(req, res) {
|
function showSearchController(req, res) {
|
||||||
const { query, page } = req.query;
|
const { query, page, adult } = req.query;
|
||||||
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
||||||
|
const includeAdult = adult == "true" ? true : false;
|
||||||
|
|
||||||
Promise.resolve()
|
if (username) {
|
||||||
.then(() => {
|
searchHistory.create(username, query);
|
||||||
if (username) {
|
}
|
||||||
return searchHistory.create(username, query);
|
|
||||||
}
|
return tmdb
|
||||||
return null;
|
.showSearch(query, page, includeAdult)
|
||||||
})
|
|
||||||
.then(() => tmdb.showSearch(query, page))
|
|
||||||
.then(shows => {
|
.then(shows => {
|
||||||
res.send(shows);
|
res.send(shows);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user