Skip to content

Commit

Permalink
Merge pull request #66 from CS179K-Summer23/ListSharingFeature
Browse files Browse the repository at this point in the history
List sharing feature
  • Loading branch information
hp6164 authored Aug 21, 2023
2 parents 2ff997a + 81d708c commit a69444d
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 4 deletions.
7 changes: 7 additions & 0 deletions BackEnd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ class moviedetails(db.Model):
rated = db.Column(db.String(10), nullable=False)




class User_watchlist(db.Model):
id = db.Column(db.Integer, primary_key=True)
userid = db.Column(db.String(50), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
movie_id = db.Column(db.String(120), unique=True, nullable=False)
28 changes: 25 additions & 3 deletions BackEnd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from functools import wraps
from flask_bcrypt import Bcrypt
import csv
import psycopg2
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy import or_
Expand Down Expand Up @@ -64,7 +63,7 @@ def decorated(*args, **kwargs):

def todays_hottest(target_genres, age=None, min_vote_count=1000, limit=25):
movies_list = []

query = db.session.query(moviedetails)

for movie in query.all():
Expand Down Expand Up @@ -239,7 +238,9 @@ def usersurvey(current_user):
#genrelist_str = json.dumps(glist)
glist = [genre.strip().lower() for genre in glist.split(",")]


result = top25_by_genre(glist)

print('This is the result')
print(result)
return result
Expand Down Expand Up @@ -311,6 +312,28 @@ def get_top_movies():
print(records)
return jsonify(records)

@app.route('/getusers', methods=['POST'])
def get_users():
ids=[]
query = db.session.query(user_watchlist)
for user in query.all():
id = user.user_id
ids.append(id)

return ids


@app.route('/getlist', methods=['POST'])
def get_list():
movielist=[]
data = request.json
name = data.get('user_id')
query = db.session.query(user_watchlist).filter_by(user_id = name)
for movie in query.all():
moviename = movie.user_id
movielist.append(moviename)
return movielist

@app.route('/movie_data', methods=['POST'])
def get_movie_data():
movie_app = MovieList(db_params)
Expand All @@ -334,7 +357,6 @@ def submit_rating():
else:
return 'Movie not found', 404


@app.route('/news')
def get_news():
articles = news_api.fetch_news()
Expand Down
13 changes: 12 additions & 1 deletion FrontEnd/pages/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default function MainApp({jsonfile, jsonfile2}) {
</ListItemIcon>
<ListItemText primary="Profile" />
</ListItemButton>
</ListItem>
</ListItem>
<ListItem key="MovieList" disablePadding>
<ListItemButton onClick={() => (setpage(5))}>
<ListItemIcon>
Expand All @@ -198,6 +198,15 @@ export default function MainApp({jsonfile, jsonfile2}) {
<ListItemText primary="MovieList" />
</ListItemButton>
</ListItem>
<ListItem key="ThreadList" disablePadding>
<ListItemButton onClick={() => (setpage(6))}>
<ListItemIcon>
<DescriptionIcon />
</ListItemIcon>
<ListItemText primary="ThreadList" />
</ListItemButton>
</ListItem>


</List>
<Divider />
Expand All @@ -209,6 +218,8 @@ export default function MainApp({jsonfile, jsonfile2}) {
{page===3 && <MovieRatings jsonfile2={jsonfile2}/> }
{page===4 && <ProfilePage />}
{page===5 && <MovieList />}
{page === 6 && <ThreadList />}

</Main>
</Box>
</ThemeProvider>
Expand Down
155 changes: 155 additions & 0 deletions FrontEnd/pages/thread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import * as React from "react";
import { ThemeProvider, createTheme, styled } from "@mui/material/styles";
import CssBaseline from "@mui/material/CssBaseline";
import { Button, Box } from "@mui/material";
import ListIcon from "@mui/icons-material/List";
import TextField from "@mui/material/TextField";
import Dialog from "@mui/material/Dialog";
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import DialogContentText from "@mui/material/DialogContentText";
import DialogTitle from "@mui/material/DialogTitle";

const lightTheme = createTheme({
palette: {
mode: "dark",
},
});

export default function Threadlist() {

const [listchoose, setlistchoose] = React.useState();
const [open, setOpen] = React.useState(false);

const handleClickOpen = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

const handleViewList = temp => {
setlistchoose(temp);
getList();
};

const getUsers = async (event) => {
event.preventDefault();

try {
const res = await axios.post('http://localhost:5000/getusers');
console.log(res);

alert(res.data);
if (res.data && res.status === 200) {
if(onSuccess){
onSuccess();
}
}
} catch (err) {
console.error(err);
}
};


const getList = async (event) => {
event.preventDefault();

try {
const res = await axios.post('http://localhost:5000/getlist', listchoose);
console.log(res.data);
movielists = res.data;
setOpen(true);
alert(res.data);
if (res.data && res.status === 200) {
if(onSuccess){
onSuccess();
}
}
} catch (err) {
console.error(err);
}
};

useEffect(() => {
getUsers();
}, []);

return (
<>
<ThemeProvider theme={lightTheme}>
<CssBaseline />
<Box
display="flex"
justifyContent="center"
alignItems="center"
sx={{
marginTop: 8,
display: "flex",
backgroundColor: "black",
align: "center",
width: "250px",
borderRadius: 8,
marginLeft: "auto",
marginRight: "auto",
}}
>
<h1>Movie Lists</h1>
</Box>
{lists.map((list, index) => {
return (
<Box
display="flex"
justifyContent="center"
alignItems="center"
sx={{
display: "flex",
marginTop: 5,
marginLeft: "38%",
marginRight: "auto",
marginBottom: "auto",
justifyContent: "flex",
flexDirection: "row",
backgroundColor: "black",
align: "center",
width: "30%",
height: "100px",
borderRadius: 5,
overflow: "hidden",
}}
>
<ListIcon />
<Button
variant="outlined"
style={{
maxWidth: "500px",
maxHeight: "100px",
minWidth: "500px",
minHeight: "100px",
}}
onClick={() => handleViewList(list.user)}
>
{list.user}
</Button>
</Box>
);
})}
<Dialog open={open} onClose={handleClose}>
<DialogTitle>{listchoose}</DialogTitle>
<DialogContent>
<DialogContentText>________List:_________</DialogContentText>
{movielists.map((m, index) => {
return (
<DialogContentText>{m.title}</DialogContentText>
);
})}
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Close</Button>
</DialogActions>
</Dialog>
</ThemeProvider>
</>
);
}

0 comments on commit a69444d

Please sign in to comment.