Skip to content

Commit

Permalink
Merge pull request #5 from CSC-510-G55/feat/lists
Browse files Browse the repository at this point in the history
feat: lists
  • Loading branch information
siriscmv authored Nov 20, 2024
2 parents c70daf8 + 4cf486f commit 34692a3
Show file tree
Hide file tree
Showing 20 changed files with 1,970 additions and 1,753 deletions.
63 changes: 63 additions & 0 deletions backend/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
OperationFailure,
DuplicateKeyError,
)
from backend.recommenderapp.utils import generate_random_string

from backend.recommenderapp.search import Search

Expand Down Expand Up @@ -234,6 +235,68 @@ def recent_movies():
return get_recent_movies(db, user[1], movies_df)


@app.route("/init", methods=["PUT"])
def init():
"""
Initializes the database with the movies
"""
movies = movies_df.to_dict(orient="records")

for movie in movies:
movie["name"] = movie["title"]
db.movies.update_one(
{"movieId": movie["movieId"]},
{"$setOnInsert": movie}, # Only insert the record if it doesn't exist
upsert=True,
)

return "Movies inserted successfully"


@app.route("/lists", methods=["POST"])
def create_list():
"""
Handles the creation of a new list
"""
data = json.loads(request.data)

list_name = data["name"] + "--" + generate_random_string(10)
movie_names = data["movies"]
user_id = ObjectId(user[1])

movies = db.movies.find({"title": {"$in": movie_names}}).distinct("_id")

print([d for d in list(db.movies.find())][:1])

print("ffdsdfsdfsdf")

print(movie_names)

db.lists.insert_one({"name": list_name, "movies": list(movies), "user_id": user_id})

return json.dumps({"slug": list_name})


@app.route("/lists/<slug>", methods=["GET"])
def get_list(slug):
"""
Gets the list with the given slug
"""
list_data = db.lists.find_one({"name": slug}, {"_id": False, "user_id": False})

movie_ids = list_data["movies"]
print(movie_ids)
movies = list(
db.movies.find({"_id": {"$in": movie_ids}}, {"_id": False, "user_id": False})
) # Exclude '_id' field

list_data["movies"] = movies

print(list_data)

return json.dumps(list_data)


@app.route("/getRecentFriendMovies", methods=["POST"])
def recent_friend_movies():
"""
Expand Down
7 changes: 7 additions & 0 deletions backend/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import pandas as pd
import os
import requests
import string
import secrets

app_dir = os.path.dirname(os.path.abspath(__file__))
code_dir = os.path.dirname(app_dir)
Expand All @@ -36,6 +38,11 @@ def load_movies():
return pd.read_csv(os.path.join("data", "movies.csv"))


def generate_random_string(length: int) -> str:
characters = string.ascii_lowercase + string.digits
return "".join(secrets.choice(characters) for _ in range(length))


def create_colored_tags(genres):
"""
Utitilty function to create colored tags for different
Expand Down
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
]
},
"devDependencies": {
"@types/node": "^22.9.1",
"@types/react": "^18.3.12",
"@types/react-autocomplete": "^1.8.11",
"prettier": "^3.3.3"
}
}
4 changes: 4 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Baring from "./components/Baring";
import SearchPage from "./components/SearchPage";
import ReviewPage from "./components/Reviews";
import SuccessPage from "./components/Success";
import Lists from "./components/Lists.tsx";
import ListDetail from "./components/ListDetail.tsx";

function App() {
return (
Expand All @@ -17,6 +19,8 @@ function App() {
<Route path="/profile" element={<ProfilePage />} />
<Route path="/landing" element={<Landing />} />
<Route path="/dashboard" element={<Baring />} />
<Route path="/lists" element={<Lists />} />
<Route path="/lists/:slug" element={<ListDetail />} />
<Route path="/search_page" element={<SearchPage />} />
<Route path="/reviews" element={<ReviewPage />} />
<Route path="/success" element={<SuccessPage />} />
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render, screen } from "@testing-library/react";
import App from "./App";
import { render, screen } from '@testing-library/react';
import App from './App';

test("renders learn react link", () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
Loading

0 comments on commit 34692a3

Please sign in to comment.