Ejemplo n.º 1
0
def create_promotion():
    """
    Create a new promotion
    This endpoint will create a promotion based on the data in the request body and save it into the db
    """
    check_content_type('application/json')
    promotion = Promotion()
    promotion.deserialize(request.get_json())
    promotion.save()
    saved_info = promotion.serialize()
    location_url = url_for('get_promotion', promotion_id = promotion.id, _external=True)
    return make_response(jsonify(saved_info), status.HTTP_201_CREATED, { 'Location': location_url })
Ejemplo n.º 2
0
 def post(self):
     """
     Create a new promotion
     This endpoint will create a promotion based on the data in the request body and save it into the db
     """
     app.logger.info('Request to Create a Promotion')
     check_content_type('application/json')
     promotion = Promotion()
     app.logger.info('Payload = %s', api.payload)
     promotion.deserialize(api.payload)
     promotion.save()
     app.logger.info('Promotion with new id [%s] saved!', promotion.id)
     location_url = api.url_for(PromotionResource,
                                promotion_id=promotion.id,
                                _external=True)
     return promotion.serialize(), status.HTTP_201_CREATED, {
         'Location': location_url
     }