+
+
diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx
index c9f64ca..6e2cc7f 100644
--- a/client/app/components/SearchRequest.jsx
+++ b/client/app/components/SearchRequest.jsx
@@ -9,6 +9,8 @@ import movieStyle from './styles/movieObjectStyle.jsx';
import URI from 'urijs';
import InfiniteScroll from 'react-infinite-scroller';
+import { fetchJSON } from './http.jsx';
+
var MediaQuery = require('react-responsive');
// TODO add option for searching multi, movies or tv shows
diff --git a/client/app/components/buttons/request_button.jsx b/client/app/components/buttons/request_button.jsx
new file mode 100644
index 0000000..5085f8d
--- /dev/null
+++ b/client/app/components/buttons/request_button.jsx
@@ -0,0 +1,22 @@
+import React from 'react';
+
+class RequestButton extends React.Component {
+ constructor() {
+ super();
+
+ this.state = {textColor: 'white'};
+ }
+
+ render() {
+ return (
+ this.setState({textColor: 'red'})}
+ onExit={() => this.setState({textColor: 'white'})}>
+ This text will turn red when you look at it.
+
+ );
+ }
+}
+
+export default RequestButton;
\ No newline at end of file
diff --git a/client/app/components/http.jsx b/client/app/components/http.jsx
new file mode 100644
index 0000000..63de148
--- /dev/null
+++ b/client/app/components/http.jsx
@@ -0,0 +1,52 @@
+import React from 'react';
+
+import { getCookie } from './Cookie.jsx';
+
+// class http {
+// dispatch(obj) {
+// console.log(obj);
+// }
+
+ function checkStatus(response) {
+ const hasError = (response.status < 200 || response.status >= 300)
+ if (hasError) {
+ throw response.text();
+ }
+ return response;
+ }
+
+ function parseJSON(response) { response.json(); }
+
+
+
+// *
+// * Retrieve search results from tmdb with added seasoned information.
+// * @param {String} uri query you want to search for
+// * @param {Number} page representing pagination of results
+// * @returns {Promise} succeeds if results were found
+
+// fetchSearch(uri) {
+// fetch(uri, {
+// method: 'GET',
+// headers: {
+// 'authorization': getCookie('token')
+// },
+// })
+// .then(response => {
+
+// });
+// }
+// }
+
+// export default http;
+
+export function fetchJSON(url, method, data) {
+ return fetch(url, {
+ method: method,
+ headers: new Headers({
+ 'Content-Type': 'application/json',
+ 'authorization': getCookie('token'),
+ }),
+ body: JSON.stringify(data)
+ }).then(checkStatus).then(parseJSON);
+ }
\ No newline at end of file
diff --git a/client/app/components/styles/requestElementStyle.jsx b/client/app/components/styles/requestElementStyle.jsx
index 8fa0c15..824fb28 100644
--- a/client/app/components/styles/requestElementStyle.jsx
+++ b/client/app/components/styles/requestElementStyle.jsx
@@ -5,6 +5,7 @@ export default {
flexDirection: 'row',
flexWrap: 'wrap',
flexFlow: 'row wrap',
+ justifyContent: 'space-around',
},
wrappingDiv: {
diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js
index ee05bde..97e5c37 100644
--- a/seasoned_api/src/plex/requestRepository.js
+++ b/seasoned_api/src/plex/requestRepository.js
@@ -20,8 +20,9 @@ class RequestRepository {
constructor(database) {
this.database = database || establishedDatabase;
this.queries = {
- 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)",
+ 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
'fetchRequstedItems': "SELECT * FROM requests",
+ 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
}
}
@@ -116,7 +117,7 @@ class RequestRepository {
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, user_agent])
+ this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, 'NULL', ip, user_agent, movie.type])
//
@@ -167,6 +168,10 @@ class RequestRepository {
return this.database.all(this.queries.fetchRequstedItems);
}
+ updateRequestedById(id, type, status) {
+ return this.database.run(this.queries.updateRequestedById, [status, id, type]);
+ }
+
}
module.exports = RequestRepository;
\ No newline at end of file
diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js
index be30da7..7cc1a67 100644
--- a/seasoned_api/src/webserver/app.js
+++ b/seasoned_api/src/webserver/app.js
@@ -67,7 +67,11 @@ router.get('/v1/plex/request/:mediaId', require('./controllers/plex/readRequest.
router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js'));
router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js'));
+/**
+ * Requests
+ */
router.get('/v1/plex/requests/all', mustBeAuthenticated, require('./controllers/plex/fetchRequested.js'));
+router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js'));
/**
* TMDB
diff --git a/seasoned_api/src/webserver/controllers/plex/updateRequested.js b/seasoned_api/src/webserver/controllers/plex/updateRequested.js
new file mode 100644
index 0000000..57b2638
--- /dev/null
+++ b/seasoned_api/src/webserver/controllers/plex/updateRequested.js
@@ -0,0 +1,24 @@
+const RequestRepository = require('src/plex/requestRepository');
+const requestRepository = new RequestRepository();
+
+/**
+ * Controller: Retrieves search history of a logged in user
+ * @param {Request} req http request variable
+ * @param {Response} res
+ * @returns {Callback}
+ */
+function updateRequested(req, res) {
+ const id = req.params.requestId;
+ const type = req.body.type;
+ const status = req.body.status;
+
+ requestRepository.updateRequestedById(id, type, status)
+ .then(() => {
+ res.send({ success: true });
+ })
+ .catch((error) => {
+ res.status(401).send({ success: false, error: error.message });
+ });
+}
+
+module.exports = updateRequested;