release
This commit is contained in:
26
main.py
26
main.py
@ -1,9 +1,29 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
import database
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Hello": "World"}
|
||||
class Message(BaseModel):
|
||||
author: str
|
||||
recipient: str
|
||||
content: str
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def read_recents(history: int = 10):
|
||||
rs = database.DB_get_recent_msgs(history)
|
||||
return rs
|
||||
|
||||
|
||||
@app.post("/msg")
|
||||
def post_msg(msg: Message):
|
||||
database.DB_new_msg(author=msg.author, recipient=msg.recipient, content=msg.content)
|
||||
return f"Message sent to {msg.recipient}"
|
||||
|
||||
|
||||
@app.get("/msg/{msg_id}")
|
||||
def get_msg(msg_id: int):
|
||||
r = database.DB_get_msg(msg_id)
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user