Beispiel #1
0
def list_promotions():
    """ Returns all of the Promotions """
    promotions = []
    category = request.args.get('category')
    name = request.args.get('name')
    availability = request.args.get('availability')
    if category:
        promotions = Promotion.find_by_category(category)
    elif name:
        promotions = Promotion.find_by_promo_name(name)
    elif availability:
        promotions = Promotion.find_by_availability(availability)
    else:
        promotions = Promotion.all()

    results = [promotion.serialize() for promotion in promotions]
    return make_response(jsonify(results), status.HTTP_200_OK)
Beispiel #2
0
    def get(self):
        """ Returns all of the Promotions"""
        app.logger.info("Request to list promotions")
        promotions = []
        category = request.args.get('category')
        name = request.args.get('promo_name')
        availability = request.args.get('availability')
        if category:
            promotions = Promotion.find_by_category(category)
        elif name:
            promotions = Promotion.find_by_promo_name(name)
        elif availability:
            availability = str_to_bool(availability)
            promotions = Promotion.find_by_availability(availability)
        else:
            promotions = Promotion.all()

        results = [promotion.serialize() for promotion in promotions]
        return results, status.HTTP_200_OK