Example #1
0
    def delete(self):
        """ Delete all unavailable Promotions

        This endpoint will delete all unavailable Promotions
        """
        promotions = Promotion.find_by_availability(False)
        if promotions:
            for promotion in promotions:
                promotion.delete()
        return '', status.HTTP_204_NO_CONTENT
Example #2
0
def delete_unavailable_promotion():

    """ Delete all unavailable Promotions """
    """ This endpoint will delete all unavailable Promotions """

    promotions = Promotion.find_by_availability(False)
    if promotions:
        for promotion in promotions:
            promotion.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Example #3
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)
Example #4
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