home · contact · privacy
Add GET /todo and Todo retrieval by ID.
[plomtask] / plomtask / todos.py
index 1b6b740c97930862b8867d5229e01685713e6595..7150f0d702c44ec89e170e5381b20c8e61ea42ae 100644 (file)
@@ -28,6 +28,13 @@ class Todo:
                    is_done=row[2],
                    day=Day.by_date(db_conn, row[3]))
 
+    @classmethod
+    def by_id(cls, db_conn: DatabaseConnection, id_: int) -> Todo:
+        """Get Todo of .id_=id_."""
+        for row in db_conn.exec('SELECT * FROM todos WHERE id = ?', (id_,)):
+            return cls.from_table_row(row, db_conn)
+        raise NotFoundException(f'Todo of ID not found: {id_}')
+
     @classmethod
     def by_date(cls, db_conn: DatabaseConnection, date: str) -> list[Todo]:
         """Collect all Todos for Day of date."""