|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
# use database residing here
|
|
|
|
|
DB_LOCATION = (
|
|
|
|
|
@ -8,7 +9,7 @@ DB_LOCATION = (
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
con = sqlite3.connect(DB_LOCATION)
|
|
|
|
|
con.row_factory = sqlite3.Row
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
cur = con.cursor() # NB! single is enough for now, we might require multiple later
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/new_session")
|
|
|
|
|
@ -32,7 +33,10 @@ async def next_picture(cookie: int):
|
|
|
|
|
)
|
|
|
|
|
sessionid = cur.fetchone()
|
|
|
|
|
if sessionid is None:
|
|
|
|
|
return
|
|
|
|
|
return {
|
|
|
|
|
"picture_id": -2,
|
|
|
|
|
"picture_uri": "/path/to/new/session/placeholder", # FIXME[2]
|
|
|
|
|
} # Q: do we return something specific, or just use convention here?
|
|
|
|
|
|
|
|
|
|
# take not rated picture from the database
|
|
|
|
|
# do not insert anything in the database yet
|
|
|
|
|
@ -55,7 +59,14 @@ async def next_picture(cookie: int):
|
|
|
|
|
{"sessionid": sessionid["sessionid"]},
|
|
|
|
|
)
|
|
|
|
|
r = cur.fetchone()
|
|
|
|
|
return {"picture_id": r["imgid"]}
|
|
|
|
|
if r is not None:
|
|
|
|
|
return {"picture_id": r["imgid"], "picture_uri": r["resizedpath"]}
|
|
|
|
|
else:
|
|
|
|
|
# All available pics have been voted for by this sessionid
|
|
|
|
|
return {
|
|
|
|
|
"picture_id": -1,
|
|
|
|
|
"picture_uri": "/path/to/you/are/done/placeholder", # FIXME[1]
|
|
|
|
|
} # Q: do we return something specific, or just use a convention here?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/rate_picture/{session_id}/{picture_id}/{mark}")
|
|
|
|
|
|