petshop-10-services.spp
petshop/cart/petshop-10-services.spp
Download original file · Petstore source contents
1domain petshop;23atomic calculate captureCartLines(Cart, CartLine[]) {4CartLine[] = new CartLine[] {5};6for (CartLine line : Cart.lines) {7CartLine[] = append(CartLine[], copy(line));8}9}1011atomic check checkCart(Buyer, Cart) {12require(Cart.buyer == Buyer, "CART_NOT_FOUND");13}1415atomic calculate addCartProduct(Goods, Cart, CartAdditionAgreement) {16CartLine[] result = new CartLine[] {17};18int previousQuantity = 0;19for (CartLine line : Cart.lines) {20if (line.goods.sku != Goods.sku) {21result = append(result, copy(line));22} else {23previousQuantity = line.quantity;24}25}26CartLine added = new CartLine();27added.buyer = Cart.buyer;28added.goods = Goods;29added.quantity = previousQuantity + CartAdditionAgreement.quantity;30Cart.lines = append(result, added);31}3233atomic calculate setCartProductQuantity(Goods, Cart, CartQuantityAgreement) {34CartLine[] result = new CartLine[] {35};36for (CartLine line : Cart.lines) {37if (line.goods.sku != Goods.sku) {38result = append(result, copy(line));39}40}41CartLine added = new CartLine();42added.buyer = Cart.buyer;43added.goods = Goods;44added.quantity = CartQuantityAgreement.quantity;45Cart.lines = append(result, added);46}4748atomic calculate removeCartProduct(Goods, Cart) {49CartLine[] result = new CartLine[] {50};51for (CartLine line : Cart.lines) {52if (line.goods.sku != Goods.sku) {53result = append(result, copy(line));54}55}56Cart.lines = result;57}5859atomic calculate clearCartProducts(Cart) {60Cart.lines = new CartLine[] {61};62}