-
Notifications
You must be signed in to change notification settings - Fork 5
Add recommend endpoint #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b3e02c5
26ccdb9
41ab228
59c31de
d48b32f
9620f56
f0302d1
f464cf1
f35b8b0
417e2c7
728303b
a7bf102
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
from mediabridge.config.backend import ENV_TO_CONFIG | ||
from mediabridge.db.tables import Base | ||
from mediabridge.recommender.make_recommendation import recommend | ||
|
||
typer_app = typer.Typer() | ||
db = SQLAlchemy(model_class=Base) | ||
|
@@ -51,6 +52,36 @@ def search_movies() -> tuple[Response, int]: | |
movies_list = [row._asdict() for row in movies] | ||
return jsonify(movies_list), 200 | ||
|
||
@app.route("/api/v1/movie/<movie_id>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Technically for REST, this would be |
||
def get_movie_by_id(movie_id): | ||
with db.engine.connect() as conn: | ||
movie = conn.execute( | ||
text("SELECT * FROM movie_title WHERE id = :id"), | ||
{"id": movie_id}, | ||
).fetchone() | ||
if not movie: | ||
return jsonify({"error": "Movie not found"}), 404 | ||
return jsonify(dict(movie._mapping)), 200 | ||
|
||
@app.route("/api/v1/movie/recommend", methods=["GET"]) # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
def recommend_movies() -> tuple[Response, int]: | ||
movies = request.args.getlist("movies[]", type=int) | ||
if not movies: | ||
return jsonify( | ||
{ | ||
"error": "Query parameter 'movies[]' is required and must be a list of integers." | ||
} | ||
), 400 | ||
if not all(isinstance(m, int) for m in movies): | ||
return jsonify({"error": "'movies' must be a list of integers."}), 400 | ||
|
||
try: | ||
rec_ids = recommend() | ||
audiodude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except Exception as e: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's considered bad practice to |
||
return jsonify({"error": f"Recommendation failed: {str(e)}"}), 500 | ||
|
||
return jsonify({"recommendations": list(rec_ids)}), 200 | ||
|
||
return app | ||
|
||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.