lvl 1
This commit is contained in:
26
main.py
Normal file
26
main.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from fastapi import FastAPI
|
||||
from contextlib import asynccontextmanager
|
||||
import database
|
||||
import models
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
database.init()
|
||||
yield
|
||||
database.close()
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
@app.post("/users")
|
||||
async def register(user: models.User):
|
||||
database.register(user)
|
||||
return user
|
||||
|
||||
@app.post("/login")
|
||||
async def login(user: models.User):
|
||||
return database.login(user)
|
||||
Reference in New Issue
Block a user