Beispiel #1
0
def get_users():

    if request.method == "GET":

        all_users = g.db.query(User).all()
        return resource_found(all_users)

    else:

        return invalid_method()
Beispiel #2
0
def get_match(match_id):

    match_id = int(match_id)
    if request.method == 'GET':

        
        return resource_found(match)
    
    else:
        
        return invalid_method()
Beispiel #3
0
def get_offer(offer_id):

    offer_id = int(offer_id)
    if request.method == "GET":

        offer = g.db.query(Offer).filter(Offer.id == offer_id).first()
        return resource_found(offer)

    else:

        return invalid_method()
Beispiel #4
0
def get_user(user_id):

    user_id = int(user_id)
    if request.method == "GET":

        user = g.db.query(User).filter(User.id == user_id).first()
        return resource_found(user)

    else:

        return invalid_method()
Beispiel #5
0
def get_offers():

    if request.method == "GET":

        latitude = request.args.get("lat", None)
        longitude = request.args.get("lng", None)
        radius = request.args.get("rad", None)
        return_users = request.args.get("users", False)

        if latitude is None or longitude is None or radius is None:

            offers = g.db.query(Offer).all()

        else:

            offers = (
                g.db.query(Offer)
                .filter(
                    and_(
                        Offer.latitude > latitude - radius,
                        Offer.latitude < latitude + radius,
                        Offer.longitude > longitude - radius,
                        Offer.longitude < longitude + radius,
                    )
                )
                .all()
            )

        if return_users:

            offer_user_ids = (x.user_id for x in offers)

            users = g.db.query(User).filter(User.id.in_(user_ids)).all()

            return multiple_resources_found(offers, users)

        else:

            return resource_found(offers)

    else:

        return invalid_method()