petshop-05-checks.spp
petshop/order/petshop-05-checks.spp
Download original file · Petstore source contents
1domain petshop;23atomic check checkQuotationInput(Cart, Goods[]) {4require(Cart.lines != null, "EMPTY_CART");5int count = 0;6for (CartLine line : Cart.lines) {7require(line != null && line.quantity != null && line.quantity > 0, "INVALID_QUANTITY");8boolean found = false;9for (Goods product : Goods[]) {10if (product.sku == line.goods.sku) {11found = true;12}13}14require(found, "PRODUCT_UNAVAILABLE");15count++;16}17require(count > 0, "EMPTY_CART");18}1920atomic check checkUnpaidCancellationAgreementInput(UnpaidCancellationAgreement) {21require(22UnpaidCancellationAgreement.reason != null && UnpaidCancellationAgreement.reason != "",23"REASON_REQUIRED"24);25}2627atomic check checkUnpaidCancellation(ShopOrder) {28require(ShopOrder.status == OrderStatus.UNPAID, "ORDER_NOT_CANCELLABLE");29}3031atomic check checkPaidCancellationAgreementInput(PaidCancellationAgreement) {32require(33PaidCancellationAgreement.reason != null && PaidCancellationAgreement.reason != "",34"REASON_REQUIRED"35);36}3738atomic check checkPaidCancellation(ShopOrder) {39require(ShopOrder.status == OrderStatus.PAID, "ORDER_NOT_CANCELLABLE");40}4142atomic check checkOrderReservation(ShopOrder, StockLine[]) {43for (OrderLine line : ShopOrder.lines) {44boolean found = false;45for (StockLine stock : StockLine[]) {46if (stock.goods.sku == line.goods.sku) {47int needed = 0;48for (OrderLine ordered : ShopOrder.lines) {49if (ordered.goods.sku == line.goods.sku) {50needed += ordered.quantity;51}52}53require(stock.available >= needed, "INSUFFICIENT_STOCK");54found = true;55}56}57require(found, "INVENTORY_ITEM_NOT_FOUND");58}59}