Пример #1
0
def delete_promotion(promotion_id):
    """
    Delete a Promotion
    This endpoint will delete a Promotion based the id specified in the path
    """
    promotion = Promotion.find(promotion_id)
    if promotion:
        promotion.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Пример #2
0
def get_promotion(promotion_id):
    """
    Retrieve a single Promotion

    This endpoint will return a Promotion based on it's id
    """
    promotion = Promotion.find(promotion_id)
    if not promotion:
        raise NotFound("Promotion with id '{}' was not found.".format(promotion_id))
    return make_response(jsonify(promotion.serialize()), status.HTTP_200_OK)
Пример #3
0
 def delete(self, promotion_id):
     """
     Delete a Promotion
     This endpoint will delete a Promotion based the id specified in the path
     """
     app.logger.info('Request to Delete a promotion with id [%s]',
                     promotion_id)
     promotion = Promotion.find(promotion_id)
     if promotion:
         promotion.delete()
     return '', status.HTTP_204_NO_CONTENT
Пример #4
0
def update_promotion(promotion_id):
    """
    Update a Promotion
    This endpoint will update a Promotion based the body that is posted
    """
    check_content_type('application/json')
    promotion = Promotion.find(promotion_id)
    if not promotion:
        raise NotFound("Promotion with id '{}' was not found.".format(promotion_id))
    promotion.deserialize(request.get_json())
    promotion.id = promotion_id
    promotion.save()
    return make_response(jsonify(promotion.serialize()), status.HTTP_200_OK)
Пример #5
0
    def get(self, promotion_id):
        """
        Retrieve a single Promotion

        This endpoint will return a Promotion based on it's id
        """
        app.logger.info("Request to Retrieve a promotion with id [%s]",
                        promotion_id)
        promotion = Promotion.find(promotion_id)
        if not promotion:
            app.logger.error('Promotion with id %d was not found.',
                             promotion_id)
            raise NotFound(
                "Promotion with id '{}' was not found.".format(promotion_id))
        return promotion.serialize(), status.HTTP_200_OK
Пример #6
0
    def put(self, promotion_id):
        """
        Update a Promotion
        This endpoint will update a Promotion based the body that is posted
        """
        app.logger.info('Request to Update a promotion with id [%s]',
                        promotion_id)
        check_content_type('application/json')
        promotion = Promotion.find(promotion_id)
        if not promotion:
            app.logger.error('Promotion with id %d was not found.',
                             promotion_id)
            raise NotFound(
                "Promotion with id '{}' was not found.".format(promotion_id))

        data = api.payload
        app.logger.info(data)
        promotion.deserialize(data)
        promotion.id = promotion_id
        promotion.save()
        return promotion.serialize(), status.HTTP_200_OK