def get_tasks(tasklist_id): """ GET /<tasklist_id>/tasks - Get all tasks that belogs to a tasklist PARAMETERS: tasklist_id - Id of tasklist token - Token given for authorization """ return render_json(to_json(models.get_tasks(tasklist_id)))
def create_task(tasklist_id): """ POST /<tasklist_id>/tasks - Create a task associating it to a tasklist PARAMETERS: tasklist_id - Id of existent TaskList model title - Title of the task completed - Status of the task """ task = request.json['model'] if TaskValidator.valid(task): task = models.create_task(tasklist_id, task['title'], task['completed']) return render_json(to_json(task)) else: return render_json('{"error": "Invalid task parameters"}'), 400
def create_tasklist(): """ POST /api/tasklists - Create a TaskList PARAMETERS: model tasklist_id - Id of tasklist password - Password to retrieve token """ task = request.json['model'] try: if TaskListValidator.valid(task): tasklist = models.create_tasklist(task['tasklist_id'], task['password']) return render_json(to_json(tasklist)) else: return render_json('{"error": "Invalid tasklist parameters"}'), 400 except TaskListAlreadyExistsException, e: return render_json('{"error": "%s"}' % e.message), 409
def update_task(tasklist_id, task_id): """ PUT /<tasklist_id>/tasks/<task_id> - Modify the status of a Task that belongs to a TaskList. PARAMETERS: tasklist_id - Id of tasklist task_id - Id of the task model title - Title of the task completed - Status of the task """ try: task = request.json['model'] if TaskValidator.valid(task): task = models.update_task(task_id, task['title'], task['completed']) return render_json(to_json(task)) else: return render_json('{"error": "Invalid parameters"}'), 400 except TaskNotFoundException as e: return render_json('{"error": %s }', e.message), 404