diff --git a/.github/workflows/mapi.yml b/.github/workflows/mapi.yml index 8005eba..ef659e6 100644 --- a/.github/workflows/mapi.yml +++ b/.github/workflows/mapi.yml @@ -11,7 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository +<<<<<<< HEAD uses: actions/checkout@v3 +======= + uses: actions/checkout@v2 +>>>>>>> c71c25e (Update mapi.yml) # Create environment to run API - name: Set up Python diff --git a/src/main.py b/src/main.py index aa77c19..7702dc8 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ from fastapi import FastAPI, Request, Response import os import sqlite3 +from os.path import isfile app = FastAPI() con = sqlite3.connect(':memory:') @@ -19,7 +20,7 @@ async def debug_exception_handler(request: Request, exc: Exception): etype=type(exc), value=exc, tb=exc.__traceback__ ) ) - ) + ) @app.on_event("startup") async def startup_event(): @@ -29,7 +30,28 @@ async def startup_event(): cur.execute('''CREATE TABLE users (email text, password text)''') cur.execute('''INSERT INTO users VALUES ('me@me.com', '123456')''') con.commit() + @app.get("/") async def root(): return {"message": "Hello World"} + + +@app.get("/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 + +@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() \ No newline at end of file