diff options
Diffstat (limited to 'sca-cpp/trunk/test/store-script/shopping-cart.scm')
-rw-r--r-- | sca-cpp/trunk/test/store-script/shopping-cart.scm | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/sca-cpp/trunk/test/store-script/shopping-cart.scm b/sca-cpp/trunk/test/store-script/shopping-cart.scm index ebb3504e25..01ca62df40 100644 --- a/sca-cpp/trunk/test/store-script/shopping-cart.scm +++ b/sca-cpp/trunk/test/store-script/shopping-cart.scm @@ -1,26 +1,58 @@ ; Shopping cart implementation -(define (post item) - (uuid) +(define cartId "1234") + +; Get the shopping cart from the cache +; Return an empty cart if not found +(define (getcart id cache) + (define cart (cache "get" id)) + (if (nul cart) + (list) + cart) +) + +; Post a new item to the cart, create a new cart if necessary +(define (post item cache) + (define id (uuid)) + (define cart (cons item (getcart cartId cache))) + (cache "put" cartId cart) + id ) -(define (getall) - (cons "Sample Feed" (cons (uuid) '())) +; Return the content of the cart +(define (getall cache) + (define cart (getcart cartId cache)) + (cons "Your Cart" (cons cartId cart)) ) -(define (get id) +; Get an item from the cart +(define (get id cache) (define entry (list (list 'name "Apple") (list 'currencyCode "USD") (list 'currencySymbol "$") (list 'price 2.99))) (cons "Item" (list id entry)) ) -(define (delete id) - true +; Delete the cart +(define (delete id cache) + (cache "delete" cartId) +) + +; Return the price of an item +(define (price item) + (car (cdr (car (cdr (cdr (cdr (cdr (car (cdr (cdr item)))))))))) +) + +; Sum the prices of a list of items +(define (sum items) + (if (nul items) 0 (+ (price (car items)) (sum (cdr items)))) ) -(define (gettotal) - 11.0 +; Return the total price of the items in the cart +(define (gettotal cache) + (define cart (getcart cartId cache)) + (sum cart) ) ; TODO remove these JSON-RPC specific functions -(define (system.listMethods) (list "Service.getTotal")) +(define (system.listMethods cache) (list "Service.getTotal")) (define Service.getTotal gettotal) + |