26 lines
506 B
Python
26 lines
506 B
Python
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) |