Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Allow POSTing PIDs right at the task creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Aug 11, 2019
1 parent 3459a39 commit c6885dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion project_amber/handlers/task.py
Expand Up @@ -69,7 +69,8 @@ def handle_task_request():
# if only I could `get("status", d=0)` like we do that with dicts
if status is None:
status = 0
new_id = addTask(text, status)
parent_id = request.json.get("parent_id") # ok to be `None`
new_id = addTask(text, status, parent_id)
return dumps({ "id": new_id })

def handle_task_id_request(task_id: int):
Expand Down
11 changes: 9 additions & 2 deletions project_amber/helpers/task.py
Expand Up @@ -6,13 +6,20 @@
from project_amber.helpers import time
from project_amber.models.task import Task

def addTask(text: str, status: int) -> int:
def addTask(text: str, status: int, parent_id: int) -> int:
"""
Creates a new task. Returns its ID.
"""
task_time = time()
gen = 0
if not parent_id is None:
parent = db.session.query(Task)\
.filter_by(id=parent_id, owner=request.user.id).one_or_none()
if parent is None:
raise NotFound(MSG_TASK_NOT_FOUND)
gen = parent.gen + 1
task = Task(owner=request.user.id, text=text, creation_time=task_time, \
last_mod_time=task_time, status=status, gen=0)
last_mod_time=task_time, status=status, parent_id=parent_id, gen=gen)
db.session.add(task)
db.session.commit()
return task.id
Expand Down

0 comments on commit c6885dd

Please sign in to comment.