-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
27 lines (23 loc) · 882 Bytes
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from model import ToDoList, Item
from uow import AbstractUnitOfWork
from datetime import date
from uuid import uuid4
def create_todo(uow: AbstractUnitOfWork) -> ToDoList:
todolist = ToDoList(to_do_id=str(uuid4()), date_created=date.today())
with uow:
uow.todo_lists.add(todolist)
uow.commit()
return todolist
def get_list(uow: AbstractUnitOfWork) -> ToDoList:
with uow:
todolist = uow.todo_lists.get()
return todolist
# id, todolist_id, title, body, completed, date_created
def create_item(title: str, body: str, completed: bool, uow: AbstractUnitOfWork) -> Item:
item = Item(item_id=str(uuid4()), title=title, body=body, completed=completed, date_created=date.today())
with uow:
todolist = uow.todo_lists.get()
todolist.add_item(item)
uow.todo_lists.save(todolist)
uow.commit()
return item