Fix review put failing when no previous review exist

This commit is contained in:
Esa Kataja
2025-05-13 20:11:38 +03:00
parent 25f528c86d
commit f00bff5f64
+32 -12
View File
@@ -93,18 +93,38 @@ async def update_review(review: ReviewIn):
f"AND user_id = {review.user_id}"
)
# Update the review
conn.execute(
"UPDATE Review SET score_song = ?, score_show = ?, score_costume = ?, text_review = ? WHERE song_id = ? AND user_id = ?",
(
review.score_song,
review.score_show,
review.score_costume,
review.text_review,
review.song_id,
review.user_id,
),
)
# Check if the review exists
review_df = conn.execute(
"SELECT * FROM Review WHERE song_id = ? AND user_id = ?",
(review.song_id, review.user_id),
).fetchdf()
if not review_df.empty:
# Update the review
conn.execute(
"UPDATE Review SET score_song = ?, score_show = ?, score_costume = ?, text_review = ? WHERE song_id = ? AND user_id = ?",
(
review.score_song,
review.score_show,
review.score_costume,
review.text_review,
review.song_id,
review.user_id,
),
)
else:
# Insert the review
conn.execute(
"INSERT INTO Review (user_id, song_id, score_song, score_show, score_costume, text_review) VALUES (?, ?, ?, ?, ?, ?)",
(
review.user_id,
review.song_id,
review.score_song,
review.score_show,
review.score_costume,
review.text_review,
),
)
# Fetch the updated review
logger.debug(