@@ -11,7 +11,7 @@ def handler(event, context):
1111from boto3 .dynamodb .conditions import Key
1212
1313app = FastAPI ()
14-
14+ handler = Mangum ( app , lifespan = "off" )
1515class Priority (IntEnum ):
1616 LOW = 3
1717 MEDIUM = 2
@@ -42,18 +42,17 @@ class TodoUpdate(BaseModel):
4242 Todo (id = 5 , title = "Estudar Flask" , done = False , priority = Priority .LOW ),
4343]
4444
45+ # Create a DynamoDB client using the default credentials and region
46+ dynamodb = boto3 .resource ("dynamodb" )
47+ table = dynamodb .Table ("todo-ascan-table" )
4548
4649@app .get ("/" )
4750def read_root ():
4851 return {"Olá" : "Ascanianos" }
4952
5053@app .get ('/todos' ,response_model = List [Todo ])
5154def get_todos ():
52- return all_todos
53-
54- # @app.get("/items/{item_id}")
55- # def read_item(item_id: int, q: str = None):
56- # return {"item_id": item_id, "q": q}
55+ return table .scan ()["Items" ]
5756
5857@app .get ('/todos/{id}' , response_model = Todo )
5958def get_todo ( id : int ):
@@ -81,7 +80,7 @@ def update_todo( id: int, update_todo: TodoUpdate):
8180 for todo in all_todos :
8281 if todo .id == id :
8382 if update_todo .title is not None :
84- todo .title = update_todo .title
83+ todo . title = update_todo .title
8584 if update_todo .done is not None :
8685 todo .done = update_todo .done
8786 if update_todo .priority is not None :
@@ -97,4 +96,3 @@ def delete_todo( id: int ):
9796 return all_todos
9897 raise HTTPException (status_code = 404 , detail = "Todo não encontrado" )
9998
100- handler = Mangum (app , lifespan = "off" )
0 commit comments