Exemplo n.º 1
0
def action_to_delete_item(cart_id, item_id):
    app.logger.info(
        'Action to delete item with id: {} from cart with id: {}'.format(
            item_id, cart_id))
    results = ShoppingCartItems.find(cart_id, item_id)
    if results:
        for item in results:
            item.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Exemplo n.º 2
0
def delete_items(cart_id, product_id):
    app.logger.info(
        'Request to delete item with id: {} from cart with id: {}'.format(
            product_id, cart_id))
    results = ShoppingCartItems.find(cart_id, product_id)
    if results:
        for item in results:
            item.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Exemplo n.º 3
0
def get_item(cart_id, item_id):
    app.logger.info(
        'Getting particular item of id: {} in Cart with id: {}'.format(
            item_id, cart_id))
    cart = ShoppingCart.find(cart_id)
    if not cart:
        raise NotFound('Cart with id: {} was not found'.format(cart_id))
    results = ShoppingCartItems.find(cart_id, item_id)
    if not results:
        raise NotFound(
            'Cart with id: {} does not have any item with id: {}'.format(
                cart_id, item_id))
    return jsonify([item.serialize() for item in results]), status.HTTP_200_OK
Exemplo n.º 4
0
def update_cartitems(cart_id, item_id):
    """ Update a cart with the given cart ID and item ID """
    app.logger.info('Updating cart with id: {} and item {}'.format(
        cart_id, item_id))
    check_content_type('application/json')
    cart = ShoppingCart.find(cart_id)
    if not cart:
        raise NotFound('Cart with id: {} was not found'.format(cart_id))

    results = ShoppingCartItems.find(cart_id, item_id)
    if not results:
        raise NotFound('CartID: {} does not have item ID {}'.format(
            cart_id, item_id))

    # process the update request
    for item in results:
        item.deserialize(request.get_json())
        item.id = item_id
        item.add()
        app.logger.info('CartID {} and item ID {} has been updated'.format(
            cart_id, item_id))
    return jsonify([item.serialize() for item in results]), status.HTTP_200_OK