def delete_todo(todo_id):
    todo = Todo.query.filter_by(id=todo_id).first()
    if not todo:
        return generate_response(404, 'Task not found.')

    db.session.delete(todo)
    db.session.commit()
    return generate_response(200, 'Task deleted.')
def add_todo():
    post_data = request.get_json()
    if not post_data:
        return generate_response(400, 'Invalid payload.')

    task = post_data.get('task')
    todo = Todo(task=task)
    db.session.add(todo)
    db.session.commit()

    return generate_response(201, 'Task added.', todo_serializer(todo))
def update_todo(todo_id):
    todo = Todo.query.filter_by(id=todo_id).first()
    if not todo:
        return generate_response(404, 'Task not found.')

    post_data = request.get_json()
    if not post_data:
        return generate_response(400, 'Invalid payload.')

    todo.done = post_data.get('done')
    db.session.commit()

    return generate_response(200, 'Task updated.', todo_serializer(todo))
Beispiel #4
0
def bad_request(e):
    return generate_response(400, 'Bad request.')
Beispiel #5
0
def not_found(e):
    return generate_response(404, 'Resource not found.')
def list_todo(todo_id):
    todo = Todo.query.filter_by(id=todo_id).first()
    if not todo:
        return generate_response(404, 'Task not found.')

    return jsonify(todo_serializer(todo))