11from fastapi import APIRouter , Path
2+
23from model import Todo , TodoItem
34
45todo_router = APIRouter ()
78
89
910@todo_router .post ("/todo" )
10- async def add_todo (todo : Todo ):
11+ async def add_todo (todo : Todo ) -> dict :
1112 todo_list .append (todo )
1213 return {
1314 "message" : "Todo added successfully."
1415 }
1516
1617
1718@todo_router .get ("/todo" )
18- async def retrieve_todo ():
19+ async def retrieve_todo () -> dict :
1920 return {
2021 "todos" : todo_list
2122 }
2223
2324
2425@todo_router .get ("/todo/{todo_id}" )
25- async def get_single_todo (todo_id : int = Path (..., title = "The ID of the todo to retrieve." )):
26+ async def get_single_todo (todo_id : int = Path (..., title = "The ID of the todo to retrieve." )) -> dict :
2627 for todo in todo_list :
2728 if todo .id == todo_id :
2829 return {
@@ -34,7 +35,7 @@ async def get_single_todo(todo_id: int = Path(..., title="The ID of the todo to
3435
3536
3637@todo_router .put ("/todo/{todo_id}" )
37- async def update_todo (todo_data : TodoItem , todo_id : int = Path (..., title = "The ID of the todo to be updated." )):
38+ async def update_todo (todo_data : TodoItem , todo_id : int = Path (..., title = "The ID of the todo to be updated." )) -> dict :
3839 for todo in todo_list :
3940 if todo .id == todo_id :
4041 todo .item = todo_data .item
@@ -47,7 +48,7 @@ async def update_todo(todo_data: TodoItem, todo_id: int = Path(..., title="The I
4748
4849
4950@todo_router .delete ("/todo/{todo_id}" )
50- async def delete_single_todo (todo_id : int ):
51+ async def delete_single_todo (todo_id : int ) -> dict :
5152 for index in range (len (todo_list )):
5253 todo = todo_list [index ]
5354 if todo .id == todo_id :
@@ -61,7 +62,7 @@ async def delete_single_todo(todo_id: int):
6162
6263
6364@todo_router .delete ("/todo" )
64- async def delete_all_todo ():
65+ async def delete_all_todo () -> dict :
6566 todo_list .clear ()
6667 return {
6768 "message" : "Todos deleted successfully."
0 commit comments