diff --git a/main.py b/main.py index 9137ff3..db9ea81 100644 --- a/main.py +++ b/main.py @@ -82,7 +82,21 @@ async def rate_picture(session_id: int, picture_id: int, mark: int): ) sessionid = cur.fetchone() 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 - 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"}