aboutsummaryrefslogtreecommitdiff
path: root/src/service/tasks.py
blob: 870002a2f47a98e279df52ba31f1885815b201ed (plain)
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 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)
    db.task_tags.insert_many(cursor, task.id, task_form.tags)
    database.commit()
    return task

def update(cursor, task: Task, task_form: ValidTaskForm) -> Task:
    db.task_tags.delete(cursor, [task.id])
    updated_task = db.tasks.update(cursor, task, task_form)
    db.task_tags.insert_many(cursor, task.id, task_form.tags)
    database.commit()
    return updated_task

def delete(cursor, task_ids: List[int]):
    db.task_tags.delete(cursor, task_ids)
    db.tasks.delete(cursor, task_ids)
    database.commit()