Merge pull request #39 from KevinMidboe/feature/api_request

Feature/api request
This commit is contained in:
2017-10-03 16:28:39 +02:00
committed by GitHub
2 changed files with 5 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ class RequestRepository {
constructor(database) {
this.database = database || establishedDatabase;
this.queries = {
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE)",
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)",
'fetchRequstedItems': "SELECT * FROM requests",
}
}
@@ -109,14 +109,14 @@ class RequestRepository {
* @param {identifier, type} the id of the media object and type of media must be defined
* @returns {Promise} If nothing has gone wrong.
*/
sendRequest(identifier, type, ip) {
sendRequest(identifier, type, ip, user_agent) {
// TODO add to DB so can have a admin page
// TODO try a cache hit on the movie item
tmdb.lookup(identifier, type).then(movie => {
// Add request to database
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, 'NULL', ip])
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, 'NULL', ip, user_agent])
//

View File

@@ -13,8 +13,9 @@ function submitRequestController(req, res) {
const id = req.params.mediaId;
const type = req.query.type;
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
var user_agent = req.headers['user-agent']
requestRepository.sendRequest(id, type, ip)
requestRepository.sendRequest(id, type, ip, user_agent)
.then(() => {
res.send({ success: true, message: 'Media item sucessfully requested!' });
})