Exemple #1
0
def create_todo():
    user_id = get_jwt_identity()
    user = Users.query.get(user_id)
    if not user:
        return jsonify({'message': "User not found"}), 404
    todo_data = request.get_json()
    schema = TodoSchema()
    todo = schema.load(todo_data)
    todo.user_id = user.id
    todo.save_db()

    return TodoSchema().jsonify(todo)
Exemple #2
0
def update(id):
    result = ToDo.query.filter_by(id=id).first()
    if result:
        data = request.json
        data = ToDoUpdateSchema().load(data)
        result = result.update_db(**data)
        return TodoSchema().jsonify(result)
    return jsonify({"result": f"Id {id} wasn't found"}), 404
Exemple #3
0
def update_todo(todo_id):
    user_id = get_jwt_identity()
    todos = Todo.query.filter_by(user_id=user_id, id=todo_id).first()
    if not todos:
        return jsonify({'message': "Todo not found"}), 404

    todo = TodoUpdateSchema().load(request.get_json())
    todos.update(**todo)
    return TodoSchema().jsonify(todos)
Exemple #4
0
def create():
    data = request.json
    todo = TodoSchema().load(data)
    todo.save_db()
    return TodoSchema().jsonify(todo)
Exemple #5
0
def get_result(id):
    data = ToDo.query.filter_by(id=id).first()
    if data:
        return TodoSchema().jsonify(data)
    return jsonify({"result": f"Id {id} wasn't found"}), 404
Exemple #6
0
def get_results():
    # results = db.session.query(ToDo).all()         - this method is pure SqlAlchemy method
    results = ToDo.query.all()  # this one works only on Flask-Sqlalchemy
    return TodoSchema().jsonify(results, many=True)
Exemple #7
0
def get_todo(todo_id):
    user_id = get_jwt_identity()
    todos = Todo.query.filter_by(user_id=user_id, id=todo_id).first()
    return TodoSchema().jsonify(todos)
Exemple #8
0
def get_todos():
    user_id = get_jwt_identity()
    todos = Todo.query.filter_by(user_id=user_id).all()
    return TodoSchema().jsonify(todos, many=True)