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}" f"AND user_id = {review.user_id}"
) )
# Update the review # Check if the review exists
conn.execute( review_df = conn.execute(
"UPDATE Review SET score_song = ?, score_show = ?, score_costume = ?, text_review = ? WHERE song_id = ? AND user_id = ?", "SELECT * FROM Review WHERE song_id = ? AND user_id = ?",
( (review.song_id, review.user_id),
review.score_song, ).fetchdf()
review.score_show,
review.score_costume, if not review_df.empty:
review.text_review, # Update the review
review.song_id, conn.execute(
review.user_id, "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 # Fetch the updated review
logger.debug( logger.debug(