petshop-05-checks.spp
petshop/returns/petshop-05-checks.spp
Download original file · Petstore source contents
1domain petshop;23atomic check checkReturnRequest(ShopOrder) {4require(ShopOrder.status == OrderStatus.DELIVERED, "ORDER_NOT_RETURNABLE");5}67atomic check checkReturnApproval(ShopOrder) {8require(ShopOrder.status == OrderStatus.RETURN_REQUESTED, "RETURN_NOT_REQUESTED");9}1011atomic check checkSoldInventory(ShopOrder, StockLine[]) {12for (OrderLine line : ShopOrder.lines) {13boolean found = false;14for (StockLine stock : StockLine[]) {15if (stock.goods.sku == line.goods.sku) {16int needed = 0;17for (OrderLine ordered : ShopOrder.lines) {18if (ordered.goods.sku == line.goods.sku) {19needed += ordered.quantity;20}21}22require(stock.sold >= needed, "SOLD_STOCK_MISSING");23found = true;24}25}26require(found, "INVENTORY_ITEM_NOT_FOUND");27}28}2930atomic check checkReturnRequestAgreementInput(ReturnRequestAgreement) {31require(ReturnRequestAgreement.reason != null && ReturnRequestAgreement.reason != "", "REASON_REQUIRED");32}