Skip to content

Commit

Permalink
implementation of user reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
nfoster1492 committed Nov 15, 2023
1 parent e3d4297 commit 239717d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CREATE TABLE IF NOT EXISTS Ratings (
movie_id INT NOT NULL,
score INT NOT NULL,
review VARCHAR(45) NULL,
time DATETIME NOT NULL,
PRIMARY KEY (idRatings),
INDEX user_id_idx (user_id ASC),
INDEX movie_id_idx (movie_id ASC),
Expand Down
13 changes: 12 additions & 1 deletion src/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

import json
import sys
import calendar
import time
import datetime
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
from utils import beautify_feedback_data, send_email_to_user, createAccount, logintoAccount, submitReview
import mysql.connector
import os
from dotenv import load_dotenv
Expand Down Expand Up @@ -107,6 +110,14 @@ def logIn():
return request.data
return 400

@app.route("/review", methods=["POST"])
def review():
data = json.loads(request.data)
d = datetime.datetime.utcnow()
timestamp = calendar.timegm(d.timetuple())
submitReview(g.db, 1, data["movie"], data["score"], data["review"], timestamp)
return request.data


@app.route("/feedback", methods=["POST"])
def feedback():
Expand Down
26 changes: 25 additions & 1 deletion src/recommenderapp/templates/review.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@

let rating = 0;

var comments = $("#comments").val()

var selectedMovie = ''; // Variable to store the selected movie

$(function () {
Expand Down Expand Up @@ -192,7 +194,29 @@

//MAKE POST CALL TO DB TO ADD MOVIE REVIEW TO TABLE

alert("Review submitted for " + selectedMovie + ". Rating: " + rating + "/10");
data = {
movie: selectedMovie,
score: rating,
review: comments,
}

$.ajax({
type: "POST",
url: "/review",
dataType: "json",
contentType: "application/json;charset=UTF-8",
traditional: "true",
cache: false,
data: JSON.stringify(data),
success: function() {
alert("Review submitted for " + selectedMovie + ". Rating: " + rating + "/10");
},
error: function() {
alert("Error submitting review.");
}
})


}

// Initial highlighting
Expand Down
7 changes: 7 additions & 0 deletions src/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,10 @@ def logintoAccount(db, username, password):
if (len(result) == 0):
return False
return True

def submitReview(db, user, movie, score, review, timestamp):
executor = db.cursor()
executor.execute("SELECT idMovies FROM movies WHERE name = %s", movie)
movie_id = executor.fetchall()[0]
executor.execute("INSERT INTO popcornpicksdb.ratings(user_id, movie_id, score, review, time) VALUES (%d, %d, %d, %s, %s);", (user, movie_id, score, review, timestamp))
db.commit()

0 comments on commit 239717d

Please sign in to comment.