Skip to content

Commit

Permalink
doc: documenting api
Browse files Browse the repository at this point in the history
  • Loading branch information
wjohnsto committed Jan 14, 2025
1 parent 80cad4a commit b0fa7a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/app/components/todos/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ async def lifespan(_: FastAPI) -> AsyncIterator[Never]:

@router.get("/", tags=["todos"])
async def all() -> Todos:
"""Gets all todos"""
todos = get_todos()
return await todos.all()


@router.get("/search", tags=["todos"])
async def search(name: str | None = None, status: TodoStatus | None = None) -> Todos:
"""Searches for todos by name and/or status"""
todos = get_todos()
return await todos.search(name, status)


@router.get("/{id}", tags=["todos"])
async def one(id: str) -> Todo:
"""Gets a todo by id"""
todos = get_todos()
return await todos.one(id)

Expand All @@ -53,6 +56,7 @@ class CreateTodo(BaseModel):

@router.post("/", tags=["todos"])
async def create(todo: CreateTodo) -> TodoDocument:
"""Creates a todo"""
todos = get_todos()
return await todos.create(todo.id, todo.name)

Expand All @@ -63,11 +67,13 @@ class UpdateTodo(BaseModel):

@router.patch("/{id}", tags=["todos"])
async def update(id: str, todo: UpdateTodo) -> Todo:
"""Updates a todo's status"""
todos = get_todos()
return await todos.update(id, todo.status)


@router.delete("/{id}", tags=["todos"])
async def delete(id: str) -> None:
"""Deletes a todo"""
todos = get_todos()
return await todos.delete(id)
2 changes: 1 addition & 1 deletion src/app/components/todos/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async def create(self, id: Optional[str], name: Optional[str]) -> TodoDocument:

async def update(self, id: str, status: TodoStatus) -> Todo:
"""
Updates a todo
Updates a todo's status
"""
dt = datetime.now(UTC)

Expand Down

0 comments on commit b0fa7a0

Please sign in to comment.