Ejemplo n.º 1
0
def get_users():
    if request.method == 'GET':
        result = User().find_all()
        return {"users_list": result}
    elif request.method == 'POST':
        userToAdd = request.get_json()
        userToAdd['latitude'] = zcdb[int(userToAdd['zipcode'])].latitude
        userToAdd['longitude'] = zcdb[int(userToAdd['zipcode'])].longitude
        newUser = User(userToAdd)
        newUser.save()
        resp = jsonify(newUser), 201
        return resp
Ejemplo n.º 2
0
def get_users():
    if request.method == 'GET':
        search_username = request.args.get('name')
        search_job = request.args.get('job')
        if search_username and search_job:
            result = User().find_by_name_and_job(search_username, search_job)
        elif search_username:
            result = User().find_by_name(search_username)
        else:
            result = User().find_all()
        return {"users_list": result}
    elif request.method == 'POST':
        userToAdd = request.get_json()
        newUser = User(userToAdd)
        newUser.save()
        resp = jsonify(newUser), 201
        return resp
Ejemplo n.º 3
0
def get_users():
    if request.method == 'GET':
        search_username = request.args.get('name')
        search_job = request.args.get('job')
        if search_username and search_job:
            users = User().find_by_name_job(
                search_username, search_job)  # not converted to DB access yet
        elif search_username:
            # return find_users_by_name(search_username) #old code left here for comparuson
            users = User().find_by_name(search_username)
        else:
            users = User().find_all()
        return {"users_list": users}
    elif request.method == 'POST':
        userToAdd = request.get_json()
        # userToAdd['id'] = generate_id() #old code left here for comparuson
        # users['users_list'].append(userToAdd) #old code left here for comparuson
        newUser = User(userToAdd)
        newUser.save()
        resp = jsonify(newUser), 201
        return resp
def get_users():
    if request.method == 'GET':

        search_id = request.args.get('id')
        search_name = request.args.get('name')

        if search_id:
            return User(db_client).find_by_id(search_id)

        elif search_name:
            return User(db_client).find_by_name(search_name)

        else:
            return User(db_client).find_all()

    elif request.method == 'POST':
        user_to_add = User(db_client, json=request.get_json())
        db_resp = user_to_add.save(db_client)

        http_resp = jsonify(user_to_add.json, 201)

        return http_resp