aboutsummaryrefslogtreecommitdiff
path: root/src/db/tasks.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/tasks.py')
-rw-r--r--src/db/tasks.py103
1 files changed, 0 insertions, 103 deletions
diff --git a/src/db/tasks.py b/src/db/tasks.py
deleted file mode 100644
index efb88d6..0000000
--- a/src/db/tasks.py
+++ /dev/null
@@ -1,103 +0,0 @@
-from sqlite3 import Cursor
-import time
-from typing import List
-
-from model.task import Task, ValidTaskForm
-from model.status import Status
-from model import difficulty, priority, status
-
-def get(cursor: Cursor, s: Status) -> List[Task]:
- cursor.execute(
- " SELECT"
- " id,"
- " created_at,"
- " updated_at,"
- " name,"
- " duration,"
- " difficulty,"
- " priority,"
- " description"
- " FROM"
- " tasks"
- " WHERE"
- " status = ?",
- (status.format(s),))
-
- res = []
-
- for task in cursor.fetchall():
- res.append(Task(
- id = task[0],
- created_at = task[1],
- updated_at = task[2],
- name = task[3],
- duration = task[4],
- difficulty = difficulty.parse(task[5]),
- priority = priority.parse(task[6]),
- description = task[7]
- ))
-
- return res
-
-def insert(cursor: Cursor, s: Status, form: ValidTaskForm):
- now = int(time.time())
- cursor.execute(
- " INSERT INTO tasks("
- " created_at,"
- " updated_at,"
- " name,"
- " duration,"
- " difficulty,"
- " priority,"
- " description,"
- " status"
- " ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
- (now, now, form.name, form.duration, difficulty.format(form.difficulty), priority.format(form.priority), form.description, status.format(s)))
-
- return Task(
- id = cursor.lastrowid,
- created_at = now,
- updated_at = now,
- name = form.name,
- duration = form.duration,
- difficulty = form.difficulty,
- priority = form.priority,
- description = form.description
- )
-
-def update(cursor: Cursor, task: Task, form: ValidTaskForm):
- now = int(time.time())
-
- cursor.execute(
- " UPDATE tasks SET"
- " updated_at = ?,"
- " name = ?,"
- " duration = ?,"
- " difficulty = ?,"
- " priority = ?,"
- " description = ?"
- " WHERE id = ?",
- (now, form.name, form.duration, difficulty.format(form.difficulty), priority.format(form.priority), form.description, task.id))
-
- return Task(
- id = task.id,
- created_at = task.created_at,
- updated_at = now,
- name = form.name,
- duration = form.duration,
- difficulty = form.difficulty,
- priority = form.priority,
- description = form.description
- )
-
-def delete(cursor: Cursor, ids: List[int]):
- if len(ids) >= 1:
- cursor.execute(
- "DELETE FROM tasks WHERE id IN (%s)" % ",".join("?"*len(ids)),
- ids)
-
-def update_status(cursor: Cursor, ids: List[int], s: Status):
- if len(ids) >= 1:
- cursor.execute(
- "UPDATE tasks SET status = ? WHERE id IN (%s)" % ",".join("?"*len(ids)),
- [status.format(s)] + ids)