diff options
author | Joris | 2020-05-31 13:59:35 +0200 |
---|---|---|
committer | Joris | 2020-05-31 13:59:35 +0200 |
commit | 0f1610333324d58acafee8c0fa9d9c9bc293b219 (patch) | |
tree | 302c37dd3751e9fe2e50ab656d56253bfd2d55fc /src/service | |
parent | 8a6e10d401eea8db0947f8c4b309b8a6256f9748 (diff) |
Use defined tags for tasks
Diffstat (limited to 'src/service')
-rw-r--r-- | src/service/tasks.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/service/tasks.py b/src/service/tasks.py new file mode 100644 index 0000000..6c3444b --- /dev/null +++ b/src/service/tasks.py @@ -0,0 +1,27 @@ +from typing import List + +from model.task import Task, ValidTaskForm +import db.tasks +import db.task_tags +import database + +def get(cursor) -> List[Task]: + return db.tasks.get(cursor) + +def create(cursor, task_form: ValidTaskForm) -> Task: + task = db.tasks.insert(cursor, task_form) + new_task_tags = db.task_tags.insert_many(cursor, task.id, task_form.tags) + database.commit() + return task + +def update(cursor, task: Task, task_form: ValidTaskForm) -> Task: + updated_task = db.tasks.update(cursor, task, task_form) + db.task_tags.delete(cursor, [task.id]) + new_task_tags = db.task_tags.insert_many(cursor, task.id, task_form.tags) + database.commit() + return updated_task + +def delete(cursor, task_ids: List[int]): + db.tasks.delete(cursor, task_ids) + db.task_tags.delete(cursor, task_ids) + database.commit() |