Ejemplo n.º 1
0
def get_user(id):
    if request.method == 'GET':
        user = User({"_id": id})
        if user.reload():
            return user
        else:
            return jsonify({"error": "User not found"}), 404
    elif request.method == 'DELETE':
        user = User({"_id": id})
        resp = user.remove()
        if resp.hasWriteConcernError() or resp.hasWriteError():
            return 404
        return {}, 204
Ejemplo n.º 2
0
def get_user(id):
    if request.method == 'GET':
        user = User({"_id": id})
        if user.reload():
            return user
        else:
            return jsonify({"error": "User not found"}), 404
    elif request.method == 'DELETE':  ## still the old version. Turn it into the DB version
        user = User({"_id": id})
        if user.remove():
            resp = jsonify(), 204
            return resp
        return jsonify({"error": "User not found"}), 404
Ejemplo n.º 3
0
def get_user(id):
    if request.method == 'GET':
        user = User({"_id": id})
        if user.reload():
            return user
        else:
            return jsonify({"error": "User not found"}), 404
    elif request.method == 'DELETE':
        user = User({"_id": id})
        resp = user.remove()
        if resp['n'] == 1:
            return jsonify({"success": "User was removed"}), 204
        return jsonify({"error": "User not found"}), 404
    elif request.method == 'PATCH':
        user = User({"_id": id})
        data = request.get_json()
        for key in data:
            user.update_user(key, data[key])
        return jsonify({"Success": "User was patched"}), 200