summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/__pycache__/main.cpython-314.pycbin0 -> 13768 bytes
-rw-r--r--backend/db.dbbin0 -> 8192 bytes
-rw-r--r--backend/main.py27
3 files changed, 26 insertions, 1 deletions
diff --git a/backend/__pycache__/main.cpython-314.pyc b/backend/__pycache__/main.cpython-314.pyc
new file mode 100644
index 0000000..803bbdc
--- /dev/null
+++ b/backend/__pycache__/main.cpython-314.pyc
Binary files differ
diff --git a/backend/db.db b/backend/db.db
new file mode 100644
index 0000000..a943443
--- /dev/null
+++ b/backend/db.db
Binary files differ
diff --git a/backend/main.py b/backend/main.py
index 0042dba..aed7ce6 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -56,6 +56,9 @@ class RequestData(BaseModel):
class BlockRequestData(BaseModel):
block: int
+class FinishRequestData(BaseModel):
+ id: int
+
class Status(Enum):
EMPTY = 0,
@@ -145,6 +148,7 @@ async def start_new_timer(data: RequestData, response: fastapi.Response, session
session_key = create_session(response)
except Exception as exception:
print("err @ key creation //", exception)
+ response.status_code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR
return "something went wrong during session key creation"
try:
@@ -166,12 +170,14 @@ async def start_new_timer(data: RequestData, response: fastapi.Response, session
print("timer id", timer_id)
except Exception as exception:
print("err @ sql stuff //", exception)
+ response.status_code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR
return "something went wrong during sql stuff"
try:
scheduler.add_job(reminder_timer_finished, 'date', run_date=end_date, id=timer_id, args=[timer_id])
except Exception as exception:
print("err @ scheduler //", exception)
+ response.status_code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR
return "something went wrong during scheduler stuff"
try:
@@ -180,6 +186,7 @@ async def start_new_timer(data: RequestData, response: fastapi.Response, session
machine_durations[data.block - 1][data.machine - 1] = data.duration * 30
except Exception as exception:
print("err @ machine_status //", exception)
+ response.status_code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR
return "something went wrong during machine_status setting somehow"
return "all good bro timer started"
@@ -213,7 +220,7 @@ def get_machine_status(data: BlockRequestData):
# --- get laundr(y/ies) information of user
@app.post("/laundry")
-def get_laundry_info(session_key: Annotated[str | None, fastapi.Cookie()] = None):
+def get_laundry_info(response: fastapi.Response, session_key: Annotated[str | None, fastapi.Cookie()] = None):
if session_key:
result = []
@@ -226,14 +233,32 @@ def get_laundry_info(session_key: Annotated[str | None, fastapi.Cookie()] = None
"start_time": 0,
"machine": 0,
"status": "RUNNING",
+ "id": -1,
}
curr_timer["duration"] = row[3]
curr_timer["start_time"] = row[2]
curr_timer["machine"] = row[5]
curr_timer["status"] = row[6]
+ curr_timer["id"] = row[0]
result.append(curr_timer)
return result
else:
+ response.status_code = fastapi.status.HTTP_401_UNAUTHORIZED
return "you got no session key cookie how am i supposed to identify you"
+
+
+# --- finish one's laundry
+@app.post("/finish")
+def finish_laundry(data: FinishRequestData, response: fastapi.Response, session_key: Annotated[str | None, fastapi.Cookie()] = None):
+ if session_key:
+ cursor.execute(f"SELECT * FROM timers WHERE id = '{data.id}'")
+ row = cursor.fetchall()[0]
+
+ if session_key != row[1]:
+ response.status_code = fastapi.status.HTTP_401_UNAUTHORIZED
+ return "session key mismatch with timer id, dubious and hence unauthorised."
+ else:
+ response.status_code = fastapi.status.HTTP_401_UNAUTHORIZED
+ return "you got no session key, cannot"