Ejemplo n.º 1
0
def macheo_informacion_user(id):

    usuario = User.query.get(id)
    if usuario is None:
        raise APIException('Usuario not found', status_code=404)
    results = usuario.serialize()

    return jsonify(results), 200
Ejemplo n.º 2
0
def get_all_cart():

    all_cart_product = Cart_Product.query.all()
    if all_cart_product is None:
        raise APIException("Not favorites was Found", status_code=404)

    return jsonify(
        [single_cart.serialize() for single_cart in all_cart_product]), 200
Ejemplo n.º 3
0
def get_planet_detail(id):
    # get all the people
    item = Planet.query.get(id)

    if item is None:
        raise APIException('Planet not found', status_code=404)

    return jsonify(item.serialize()), 200
Ejemplo n.º 4
0
    def get_buy_in(user_id):

        buyin = Buy_ins.query.filter_by(user_id=user_id).order_by(
            Buy_ins.id.desc()).first()
        if buyin is None:
            raise APIException('Buy_in not found', 404)

        return jsonify(buyin.serialize()), 200
Ejemplo n.º 5
0
def delete_favorites(id):
    current_user = get_jwt_identity()
    favorite1 = Favorites.query.get(id)
    if favorite1 is None:
        raise APIException("Favorite is not found", status_code=404)
    db.session.delete(favorite1)
    db.session.commit()
    return jsonify({"Succesfully": current_user}), 200
Ejemplo n.º 6
0
def get_one_planet(position):
    planet = Planets.query.filter_by(id=position)
    request = list(map(lambda planet: planet.serialize(), planet))

    # Verify if planet exist
    if not request:
        raise APIException('Planet not found', status_code=404)
    return jsonify(request), 200
Ejemplo n.º 7
0
def get_single_contact(user_id):
    """
    Single contact
    """

    # PUT request
    if request.method == 'PUT':
        body = request.get_json()
        if body is None:
            raise APIException(
                "You need to specify the request body as a json object",
                status_code=400)

        user1 = User.query.get(user_id)
        if user1 is None:
            raise APIException('User not found', status_code=404)

        if "name" in body:
            user1.name = body["name"]
        if "password" in body:
            user1.password = body["password"]
        if "email" in body:
            user1.email = body["email"]
        if "zipcode" in body:
            user1.zipcode = body["zipcode"]
        db.session.commit()

        return jsonify(user1.serialize()), 200

# GET request
    if request.method == 'GET':
        user1 = User.query.get(user_id)
        if user1 is None:
            raise APIException('User not found', status_code=404)
        return jsonify(user1.serialize()), 200

# DELETE request
    if request.method == 'DELETE':
        user1 = User.query.get(user_id)
        if user1 is None:
            raise APIException('User not found', status_code=404)
        db.session.delete(user1)
        db.session.commit()
        return "ok", 200

    return "Invalid Method", 404
Ejemplo n.º 8
0
def add_new_plant(user_id, room_id):  
    body = request.get_json()
    if body is None:
        raise APIException("You need to specify the request body as a json object", status_code=400)
    if 'id_room' not in body:
        raise APIException('You need to specify the id room', status_code=400)
    if 'name_plant' not in body:
        raise APIException('You need to specify the name of the plant', status_code=400)
    if 'type_plant' not in body:
        raise APIException('You need to specify the type of plant', status_code=400)
    if 'grow_phase' not in body:
        raise APIException('You need to specify the grow phase', status_code=400)

    new_plant = Plants(id_room=body['id_room'], name_plant=body["name_plant"], type_plant=body["type_plant"], grow_phase=body["grow_phase"], sensor_number=body["sensor_number"])
    new_plant.create()

    return ({'status': 'OK', 'message': 'Plant Added succesfully'}), 200
Ejemplo n.º 9
0
def listarItem(id):
    #todo1 = Todo.query.get(id)
    todo1 = Todo.query.filter_by(id=id).first()
    if todo1 is None:
        return APIException({"message": "No se encontro el item"},
                            status_code=404)
    request = todo1.serialize()
    return jsonify(request), 200
Ejemplo n.º 10
0
def get_single_client(client_id):
    """
    Single client
    """

    # *******************   PUT REQUEST    *******************
    if request.method == 'PUT':
        body = request.get_json()
        if body is None:
            raise APIException(
                "You need to specify the request body as a json object",
                status_code=400)

        client1 = Client.query.get(client_id)
        if client1 is None:
            raise APIException('Client not found', status_code=404)

        if "email" in body:
            client1.email = body["email"]
        if "password" in body:
            client1.password = body["password"]
        if "client_login_status" in body:
            client1.client_login_status = body["client_login_status"]

        db.session.commit()
        return jsonify(client1.serialize()), 200

# *******************   GET REQUEST    *******************
    if request.method == 'GET':
        client1 = Client.query.get(client_id)
        if client1 is None:
            raise APIException('Client not found', status_code=404)

        return jsonify(client1.serialize()), 200

# *******************   DELETE REQUEST    *******************
    if request.method == 'DELETE':
        client1 = Client.query.get(client_id)
        if client1 is None:
            raise APIException('Client not found', status_code=404)

        db.session.delete(client1)
        db.session.commit()
        return "ok", 200

    return "Invalid Method", 404
Ejemplo n.º 11
0
def get_member(member_id):

    member = jackson_family.get_member(member_id)

    if not member:
        raise APIException('Member not found', status_code=404)

    return jsonify(member), 200
Ejemplo n.º 12
0
def delete_a_member(member_id):
    # search for this member
    member = jackson_family.get_member(int(member_id))
    if member is None:
        raise APIException("This member does not exist", 400)
    member = jackson_family.delete_member(member_id)
    response_body = "Success"
    return jsonify(response_body), 200
Ejemplo n.º 13
0
def get_single_person(person_id):
    """
    Single person
    """

    # PUT request
    if request.method == 'PUT':
        body = request.get_json()
        if body is None:
            raise APIException(
                "You need to specify the request body as a json object",
                status_code=400)

        user1 = Person.query.get(person_id)
        if user1 is None:
            raise APIException('User not found', status_code=404)

        if "fullname" in body:
            user1.fullname = body["fullname"]
        if "email" in body:
            user1.email = body["email"]
        if 'phone' in body:
            user1.phone = body['phone']
        if 'address' in body:
            user1.address = body['address']
        db.session.commit()

        return jsonify(user1.serialize()), 200

    # GET request
    if request.method == 'GET':
        user1 = Person.query.get(person_id)
        if user1 is None:
            raise APIException('User not found', status_code=404)
        return jsonify(user1.serialize()), 200

    # DELETE request
    if request.method == 'DELETE':
        user1 = Person.query.get(person_id)
        if user1 is None:
            raise APIException('User not found', status_code=404)
        db.session.delete(user1)
        db.session.commit()
        return "ok", 200

    return "Invalid Method", 404
Ejemplo n.º 14
0
def personaje_unico(id):

    personaje = Personajes.query.get(id)
    if personaje is None:
        raise APIException('Personaje not found', status_code=404)
    results = personaje.serialize2()

    return jsonify(results), 200
Ejemplo n.º 15
0
def get_one_favorite(position):
    favorite = Favorites.query.filter_by(id=position)
    request = list(map(lambda favorite: favorite.serialize(), favorite))

    # Verify if a favorite exist
    if not request:
        raise APIException('Favorite not found', status_code=404)
    return jsonify(request), 200
Ejemplo n.º 16
0
def delete_contact(id):
    contact = Contact.query.get(id)
    if contact is None:
        raise APIException('User not found', status_code=404)
    db.session.delete(contact)
    db.session.commit()
    response_body = {"msg": "Hello, you just deleted a contact"}
    return jsonify(response_body), 200
Ejemplo n.º 17
0
def get_one_user(position):
    user = User.query.filter_by(id=position)
    request = list(map(lambda user: user.serialize(), user))

    # Verify if user exist
    if not request:
        raise APIException('User not found', status_code=404)
    return jsonify(request), 200
Ejemplo n.º 18
0
def del_to_do(fid):

    task = To_do.query.filter_by(id=numb).first()
    if task is None:
        raise APIException('Not found', status_code=405)
    db.session.delete(task)
    db.session.commit()
    return jsonify({"Task deleted": numb}), 200
Ejemplo n.º 19
0
def get_one_person(position):
    person = People.query.filter_by(id=position)
    request = list(map(lambda person: person.serialize(), person))

    # Verify if person exist
    if not request:
        raise APIException('Character not found', status_code=404)
    return jsonify(request), 200
def addTodo():

    if not request.data or request.is_json is not True:
        raise APIException('Missing JSON object', status_code=405)

    label = request.json.get("label", None)

    if not label:
        raise APIException('Missing label parameter', status_code=405)

    todo = Todo()
    todo.label = label

    db.session.add(todo)
    db.session.commit()

    return jsonify("Successful operation"), 200
Ejemplo n.º 21
0
def create_swap():

    id = int(get_jwt()['sub'])

    # get sender user
    sender = Profiles.query.get(id)
    if not sender:
        raise APIException('User not found', 404)

    body = request.get_json()
    check_params(body, 'tournament_id', 'recipient_id', 'percentage')

    # get recipient user
    recipient = Profiles.query.get(body['recipient_id'])
    if not recipient:
        raise APIException('Recipient user not found', 404)

    if Swaps.query.get((id, body['recipient_id'], body['tournament_id'])):
        raise APIException('Swap already exists, can not duplicate', 400)

    sender_availability = sender.available_percentage(body['tournament_id'])
    if body['percentage'] > sender_availability:
        raise APIException((
            'Swap percentage too large. You can not exceed 50% per tournament. '
            f'You have available: {sender_availability}%'), 400)

    recipient_availability = recipient.available_percentage(
        body['tournament_id'])
    if body['percentage'] > recipient_availability:
        raise APIException(
            ('Swap percentage too large for recipient. '
             f'He has available to swap: {recipient_availability}%'), 400)

    db.session.add(
        Swaps(sender_id=id,
              tournament_id=body['tournament_id'],
              recipient_id=body['recipient_id'],
              percentage=body['percentage']))
    db.session.add(
        Swaps(sender_id=body['recipient_id'],
              tournament_id=body['tournament_id'],
              recipient_id=id,
              percentage=body['percentage']))
    db.session.commit()

    return jsonify({'message': 'ok'}), 200
Ejemplo n.º 22
0
async def get_block_filters_batch_headers(request):
    log = request.app["log"]
    log.info("GET %s" % str(request.rel_url))

    status = 500
    response = {
        "error_code": INTERNAL_SERVER_ERROR,
        "message": "internal server error",
        "details": ""
    }
    filter_type = int(request.match_info['filter_type'])
    start_height = int(request.match_info['start_height'])
    stop_hash = request.match_info['stop_hash']

    try:
        try:
            stop_hash = s2rh(stop_hash)
            if len(stop_hash) != 32:
                raise Exception()
        except:
            raise APIException(INVALID_BLOCK_POINTER, "invalid stop hash")

        if filter_type < 1:
            raise APIException(PARAMETER_ERROR, "invalid filter_type")

        if start_height < 0:
            raise APIException(PARAMETER_ERROR, "invalid start_height")

        response = await block_filters_batch_headers(filter_type, start_height,
                                                     stop_hash, log,
                                                     request.app)
        status = 200
    except APIException as err:
        status = err.status
        response = {
            "error_code": err.err_code,
            "message": err.message,
            "details": err.details
        }
    except Exception as err:
        if request.app["debug"]:
            log.error(str(traceback.format_exc()))
        else:
            log.error(str(err))
    finally:
        return web.json_response(response, dumps=json.dumps, status=status)
Ejemplo n.º 23
0
def delete_user(id):
    current_user = get_jwt_identity()
    user1 = User.query.get(id)
    if user1 is None:
        raise APIException("User is not found", status_code=404)
    db.session.delete(user1)
    db.session.commit()
    return jsonify({"Succesfully": current_user}), 200
Ejemplo n.º 24
0
def addQueue():
    user = request.get_json()

    queue.enqueue(user)

    body = request.get_json()

    if body is None:
        raise APIException("Its empty", status_code=400)
    if 'name' not in body:
        raise APIException('You need to add name', status_code=400)
    if 'phone' not in body:
        raise APIException('you need to specify the phone', status_code=400)
    queue.enqueue(body)
    return "ok", 200

    return jsonify(user)
Ejemplo n.º 25
0
def delete_user(id):
    user = User.query.get(id)
    if user is None:
        raise APIException('User not found', status_code=404)
    user.is_active = False
    DBManager.commitSession()

    return jsonify(user.serialize()), 200
Ejemplo n.º 26
0
def update_contact(contact_id):
    body = request.get_json()
    if body is None:
        raise APIException("You need to specify the request body as a json object", status_code=400)
    user1 = Contact.query.get(contact_id)
    if user1 is None:
        raise APIException('User not found', status_code=404)
    if "full_name" in body:
        user1.full_name = body["full_name"]
    if "email" in body:
        user1.email = body["email"]
    if "phone" in body:
        user1.phone = body["phone"]
    if "address" in body:
        user1.address = body["address"]
    db.session.commit()
    return jsonify(user1.serialize()), 200
Ejemplo n.º 27
0
def get_people_detail(id):
    # get all the people
    item = Character.query.get(id)

    if item is None:
        raise APIException('Character not found', status_code=404)

    return jsonify(item.serialize()), 200
Ejemplo n.º 28
0
def delete_user(user_id):
    
    user1 = User.query.get(user_id)
    if user1 is None:
        raise APIException('User not found', status_code=404)
    db.session.delete(user1)
    db.session.commit()
    return jsonify(user1.serialize()), 200
Ejemplo n.º 29
0
def get_user_favorites(id):
    # get all the people
    item = User.query.get(id)

    if item is None:
        raise APIException('User not found', status_code=404)

    return jsonify(item.serializeFavorites()), 200
Ejemplo n.º 30
0
def favoritos_unico(id):

    favoritos = Favoritos.query.get(id)
    if favoritos is None:
        raise APIException('Favorito not found', status_code=404)
    results = favoritos.serialize2()

    return jsonify(results), 200