add: img rating fn

main
rrr-marble 5 years ago
parent 588a1f2ee4
commit 854514532a

@ -82,7 +82,21 @@ async def rate_picture(session_id: int, picture_id: int, mark: int):
) )
sessionid = cur.fetchone() sessionid = cur.fetchone()
if sessionid is None: if sessionid is None:
return # FIXME[2] # Q: do we return something specific, or just use convention here? return {
"status": "failure" # FIXME[2]
} # Q: do we return something specific, or just use convention here?
# add new mark to the session table # add new mark to the session table
pass try:
cur.execute(
"""INSERT INTO marks(imgid, sessionid, mark)
VALUES(:imgid,:sessionid,:mark)
""",
{"imgid": picture_id, "sessionid": sessionid["sessionid"], "mark": mark},
)
except sqlite3.IntegrityError as e:
if str(e) == "UNIQUE constraint failed: marks.imgid, marks.sessionid":
return {"status": "already rated"}
cur.commit()
return {"status": "success"}

Loading…
Cancel
Save