| 1 |
from dataclasses import dataclass |
| 2 |
from typing import List |
| 3 |
|
| 4 |
from litestar import Litestar, get |
| 5 |
from litestar.params import FromQuery |
| 6 |
|
| 7 |
|
| 8 |
@dataclass |
| 9 |
class TodoItem: |
| 10 |
title: str |
| 11 |
done: bool |
| 12 |
|
| 13 |
|
| 14 |
TODO_LIST: List[TodoItem] = [ |
| 15 |
TodoItem(title="Start writing TODO list", done=True), |
| 16 |
TodoItem(title="???", done=False), |
| 17 |
TodoItem(title="Profit", done=False), |
| 18 |
] |
| 19 |
|
| 20 |
|
| 21 |
@get("/") |
| 22 |
async def get_list(done: FromQuery[bool]) -> List[TodoItem]: |
| 23 |
return [item for item in TODO_LIST if item.done == done] |
| 24 |
|
| 25 |
|
| 26 |
app = Litestar([get_list]) |