diff --git a/src/recommenderapp/app.py b/src/recommenderapp/app.py index 2da1dc44e..4b75e0ff4 100644 --- a/src/recommenderapp/app.py +++ b/src/recommenderapp/app.py @@ -13,7 +13,7 @@ from flask import Flask, jsonify, render_template, request, g from flask_cors import CORS from search import Search -from utils import beautify_feedback_data, send_email_to_user, createAccount, logintoAccount, submitReview +from utils import beautify_feedback_data, send_email_to_user, createAccount, logintoAccount, submitReview, getWallPosts import mysql.connector import os from dotenv import load_dotenv @@ -137,6 +137,10 @@ def review(): submitReview(g.db, 1, data["movie"], data["score"], data["review"], timestamp) return request.data +@app.route("/getWallData", methods=["GET"]) +def wallPosts(): + return getWallPosts(g.db) + @app.route("/feedback", methods=["POST"]) def feedback(): @@ -166,7 +170,6 @@ def success(): @app.before_request def before_request(): - print('opening db connection') load_dotenv() g.db = mysql.connector.connect(user='root', password=os.getenv('DB_PASSWORD'), host='127.0.0.1', @@ -174,7 +177,6 @@ def before_request(): @app.after_request def after_request(response): - print('closing db connection') g.db.close() return response diff --git a/src/recommenderapp/static/wall.js b/src/recommenderapp/static/wall.js index 076593634..292f5e9eb 100644 --- a/src/recommenderapp/static/wall.js +++ b/src/recommenderapp/static/wall.js @@ -1,26 +1,29 @@ -const posts = [ - { username: 'User1', movie: 'Movie1', review: 4, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', imdbID:'tt0086190' }, - { username: 'User2', movie: 'Movie1', review: 3.5, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', imdbID:'tt0371746' }, - { username: 'User3', movie: 'Movie1', review: 2, comment:'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', imdbID:'tt0126029' }, - { username: 'User1', movie: 'Movie1', review: 4, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', imdbID:'tt0415306' }, - { username: 'User2', movie: 'Movie1', review: 3.5, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', imdbID:'tt0120484' }, - { username: 'User3', movie: 'Movie1', review: 2, comment:'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', imdbID:'tt0317219' }, - ]; +posts = [] +function loadPosts(){ - $(document).ready(function () { - renderPosts(); - }); - - var result = ''; + return new Promise(function(resolve, reject){ + $.ajax({ + type: 'GET', + url: '/getWallData', + contentType: "application/json;charset=UTF-8", + success: function(response) { + console.log(response) + resolve(response) + }, + error: function(error) { + reject(error); + } + }); + }); +} - function fetchMovieData(imdbID){ +function fetchMovieData(imdbID){ var apikey = '77da67f1'; - - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject){ $.ajax({ type: 'GET', url: 'http://www.omdbapi.com/', @@ -35,15 +38,15 @@ const posts = [ error: function(error) { reject(error); } + }); }); - }); - } +} - async function renderPosts() { +async function renderPosts() { const postContainer = $('#post-container'); posts.forEach(post => buildPost(post, postContainer)); - } +} async function buildPost(post, postContainer){ @@ -54,7 +57,7 @@ async function buildPost(post, postContainer){ var movieData; try{ - movieData = await fetchMovieData(post.imdbID); + movieData = await fetchMovieData(post.imdb_id); } catch(error){ console.error(error); } @@ -73,17 +76,17 @@ async function buildPost(post, postContainer){ var reviewDiv = $('