-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (38 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI, status, Query
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from typing import Annotated
from constants._data import fake_items_db
from schemas.user import UserSchema
app = FastAPI()
@app.get("/items", tags=["get items"])
async def get_items(query: Annotated[str | None, Query(alias="query-mal", title="Query string here...", description="query string des", deprecated=True, min_length=3)] = None):
print(query)
results: dict[str, list[dict[str, str]]] = {
"items": [
{"item_id": "Foo"},
{"item_id": "Bar"}
]
}
if query:
results.update({"query": query})
return results
@app.post("/create", tags=["Create User"])
async def create(user: UserSchema) -> UserSchema:
print(user)
encoded = jsonable_encoder(user)
# return encoded
return JSONResponse(status_code=status.HTTP_201_CREATED, content=encoded)
@app.get("/")
async def getPost(q: str, name: str = None):
print(q)
print(name)
return {"message": "get post"}
@app.get("/find")
async def read(skip: int = 0, limit: int = 10) -> list[dict]:
print(skip)
print(limit)
print(fake_items_db[skip: skip + limit])
return {
"message": "hello"
}