Fix review put failing when no previous review exist
This commit is contained in:
@@ -93,6 +93,13 @@ async def update_review(review: ReviewIn):
|
|||||||
f"AND user_id = {review.user_id}"
|
f"AND user_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
|
# Update the review
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"UPDATE Review SET score_song = ?, score_show = ?, score_costume = ?, text_review = ? WHERE song_id = ? AND user_id = ?",
|
"UPDATE Review SET score_song = ?, score_show = ?, score_costume = ?, text_review = ? WHERE song_id = ? AND user_id = ?",
|
||||||
@@ -105,6 +112,19 @@ async def update_review(review: ReviewIn):
|
|||||||
review.user_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(
|
||||||
|
|||||||
Reference in New Issue
Block a user