Skip to content

Commit

Permalink
Added Jobs and Attachments endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vlussenburg committed Jan 9, 2023
1 parent 69a1cdc commit bb780ed
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import FastAPI, Request, Response
from fastapi import FastAPI, Request, Response, HTTPException
import os
import sqlite3
from os.path import isfile

app = FastAPI()
con = sqlite3.connect(':memory:')
Expand Down Expand Up @@ -36,12 +37,33 @@ async def root():
return {"message": "Hello World"}


@app.get("/login")
@app.post("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))
return cur.fetchone() is not None
if not cur.fetchone():
raise HTTPException(status_code=401, detail="Unknown username/password")

return email;

@app.get("/logout")
async def root(email: str):
return {"message": "Logged out %s!" % email}

@app.get("/attachment")
async def attachment(attachment_name: str):
attachment_path = 'attachments/' + attachment_name
if not isfile(attachment_path):
raise HTTPException(status_code=404, detail="Attachment not found")

with open(attachment_path) as f:
return f.readlines()

@app.post("/job")
async def job(job_name: str):
job_path = 'jobs/' + job_name
if not isfile(job_path):
raise HTTPException(status_code=404, detail="Job not found")

exec(open(job_path).read())

0 comments on commit bb780ed

Please sign in to comment.