Added user history saving and that tmdb now gets to use cache.

This commit is contained in:
2017-10-22 17:01:26 +02:00
parent d90197b8b4
commit 6574c087bc
2 changed files with 42 additions and 33 deletions

View File

@@ -1,17 +1,28 @@
const SearchHistory = require('src/searchHistory/searchHistory');
const Cache = require('src/tmdb/cache');
const RequestRepository = require('src/plex/requestRepository.js');
const requestRepository = new RequestRepository();
const cache = new Cache();
const requestRepository = new RequestRepository(cache);
const searchHistory = new SearchHistory();
function searchRequestController(req, res) {
const user = req.headers.loggedinuser;
const { query, page, type } = req.query;
console.log('searchReq: ' + query, page, type);
requestRepository.searchRequest(query, page, type)
Promise.resolve()
.then(() => {
if (user) {
return searchHistory.create(user, query);
}
return null;
})
.then(() => requestRepository.searchRequest(query, page, type))
.then((searchResult) => {
// Verify that respond has content, if so send the content back
if (searchResult.results.length > 0) {
res.send(searchResult);
}
// If no content was found, send 404 status and error message
else {
res.status(404).send({success: false, error: 'Search query did not return any results.'})
}