package de.czyrux.store.core.domain.cart;

import rx.Observable;

public class CartService {

    private final CartDataSource cartDataSource;
    private final CartStore cartStore;

    public CartService(CartDataSource cartDataSource, CartStore cartStore) {
        this.cartDataSource = cartDataSource;
        this.cartStore = cartStore;
    }

    public Observable<Cart> getCart() {
        return cartDataSource.getCart()
                .compose(cartPublisher())
                .flatMap(cart -> cartStore.observe());
    }

    public Observable<Cart> addProduct(CartProduct cartProduct) {
        return cartDataSource.addProduct(cartProduct)
                .compose(cartPublisher());
    }

    public Observable<Cart> removeProduct(CartProduct cartProduct) {
        return cartDataSource.removeProduct(cartProduct)
                .compose(cartPublisher());
    }

    private Observable.Transformer<Cart, Cart> cartPublisher() {
        return cartObservable -> cartObservable.doOnNext(cartStore::publish);
    }
}

@@ -334,32 +334,160 @@
 rtStore;%0A    %7D%0A%0A
+    /**%0A     * Gets Cart. This Observable will receive updates every time that the%0A     * underlying Cart gets updated.%0A     */%0A
     public Obser
@@ -506,24 +506,24 @@
 getCart() %7B%0A
-
         retu
@@ -646,32 +646,82 @@
 erve());%0A    %7D%0A%0A
+    /**%0A     * Add a product to the Cart.%0A     */%0A
     public Obser
@@ -870,24 +870,77 @@
 ());%0A    %7D%0A%0A
+    /**%0A     * Remove a product to the Cart.%0A     */%0A
     public O

Add documentation in CartService