Ejemplo n.º 1
0
def callback(ch, method, properties, body):
    print('Received in main')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product_created':
        product = Product(
            id=data['id'],
            sku=data['sku'],
            name=data['name'],
            price=data['price'],
            brand=data['brand'],
            image=data['image'],
            views=data['views']
        )
        db.session.add(product)
        db.session.commit()
        print('Product Created')

    elif properties.content_type == 'product_updated':
        product = Product.query.get(data['id'])
        product.sku = data['sku']
        product.name = data['name']
        product.price = data['price']
        product.brand = data['brand']
        product.image = data['image']
        product.views = data['views']
        db.session.commit()
        print('Product Updated')

    elif properties.content_type == 'product_deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print('Product Deleted')
Ejemplo n.º 2
0
def callback(ch, method, properties, body):
    print('Receieved in client')
    data = json.loads(body)
    print(body, data)
    if properties.content_type == "product_created":
        product = Product(id=data['id'], title=data['title'], image=data['image'],
                          price=data['price'], discounted_price=data['discounted_price'])
        db.session.add(product)
        db.session.commit()
    elif properties.content_type == "product_updated":
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        product.price = data['price']
        product.discounted_price = data['discounted_price']
        db.session.commit()
    elif properties.content_type == "product_deleted":
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()