diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-05 10:09:07 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-05 10:09:07 +0000 |
commit | aa27694514363589150efe13249ce9ea39694d63 (patch) | |
tree | a9904200905b29c25174171926ce6f03a1a5e32e /sca-cpp | |
parent | d9cb40f1b526f739002137e1f1a08b2d8ae0d718 (diff) |
Fixed shopping cart delete function. Map HTTP delete with no path info to a deleteall function, to distinguish delete of a resource and delete of the whole collection of resources.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@895970 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp')
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.cpp | 20 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-script/shopping-cart.scm | 9 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-script/store-script-test.cpp | 6 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-script/store-script-test.scm (renamed from sca-cpp/trunk/test/store-script/store-script.scm) | 0 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-script/store.scm | 4 |
5 files changed, 30 insertions, 9 deletions
diff --git a/sca-cpp/trunk/modules/server/mod-eval.cpp b/sca-cpp/trunk/modules/server/mod-eval.cpp index c5e71e108c..dbfe8b6221 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.cpp +++ b/sca-cpp/trunk/modules/server/mod-eval.cpp @@ -111,7 +111,7 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>& return httpd::writeResult(json::jsonResult(id, content(val), cx), "application/json-rpc", r); } - // Evaluate an ATOM GET request and return an ATOM feed + // Evaluate an ATOM GET request and return an ATOM feed representing a collection of resources const list<value> path(httpd::pathValues(r->uri)); if (isNil(cddr(path))) { const failable<value> val = failableResult(impl(cons<value>("getall", list<value>()))); @@ -120,7 +120,7 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>& return httpd::writeResult(atom::writeATOMFeed(atom::feedValuesToElements(content(val))), "application/atom+xml;type=feed", r); } - // Evaluate an ATOM GET and return an ATOM entry + // Evaluate an ATOM GET and return an ATOM entry representing a resource const failable<value> val = failableResult(impl(cons<value>("get", mklist<value>(caddr(path))))); if (!hasContent(val)) return mkfailure<int>(reason(val)); @@ -156,7 +156,7 @@ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)> return httpd::writeResult(json::jsonResult(id, content(val), cx), "application/json-rpc", r); } - // Evaluate an ATOM POST request and return the created resource location + // Evaluate an ATOM POST request and return the location of the corresponding created resource if (contains(ct, "application/atom+xml")) { // Evaluate the request expression @@ -182,7 +182,7 @@ const failable<int> put(request_rec* r, const lambda<value(const list<value>&)>& debug(r->uri, "modeval::put::url"); debug(ls, "modeval::put::input"); - // Evaluate an ATOM PUT request + // Evaluate an ATOM PUT request and update the corresponding resource const list<value> path(httpd::pathValues(r->uri)); const value entry = atom::entryValue(content(atom::readEntry(ls))); const failable<value> val = failableResult(impl(cons<value>("put", mklist<value>(caddr(path), entry)))); @@ -201,6 +201,18 @@ const failable<int> del(request_rec* r, const lambda<value(const list<value>&)>& // Evaluate an ATOM delete request const list<value> path(httpd::pathValues(r->uri)); + if (isNil(cddr(path))) { + + // Delete a collection of resources + const failable<value> val = failableResult(impl(cons<value>("deleteall", list<value>()))); + if (!hasContent(val)) + return mkfailure<int>(reason(val)); + if (val == value(false)) + return HTTP_NOT_FOUND; + return OK; + } + + // Delete a resource const failable<value> val = failableResult(impl(cons<value>("delete", mklist<value>(caddr(path))))); if (!hasContent(val)) return mkfailure<int>(reason(val)); diff --git a/sca-cpp/trunk/test/store-script/shopping-cart.scm b/sca-cpp/trunk/test/store-script/shopping-cart.scm index b7672345d7..60981411c7 100644 --- a/sca-cpp/trunk/test/store-script/shopping-cart.scm +++ b/sca-cpp/trunk/test/store-script/shopping-cart.scm @@ -39,11 +39,16 @@ (find id (getcart cartId cache)) ) -; Delete the cart -(define (delete id cache) +; Delete the whole cart +(define (deleteall cache) (cache "delete" cartId) ) +; Delete an item from the cart +(define (delete id cache) + true +) + ; Return the price of an item (define (price item) (cadr (assoc 'price (caddr item))) diff --git a/sca-cpp/trunk/test/store-script/store-script-test.cpp b/sca-cpp/trunk/test/store-script/store-script-test.cpp index 05aefcaf8c..33b87037f1 100644 --- a/sca-cpp/trunk/test/store-script/store-script-test.cpp +++ b/sca-cpp/trunk/test/store-script/store-script-test.cpp @@ -39,7 +39,7 @@ using namespace tuscany; bool testScript() { gc_scoped_pool pool; - ifstream is("store-script.scm"); + ifstream is("store-script-test.scm"); ostringstream os; scheme::evalDriverRun(is, os, pool); assert(contains(str(os), "(\"Sample Feed\" \"")); @@ -52,7 +52,7 @@ bool testScript() { bool testEval() { { gc_scoped_pool pool; - ifstream is("store-script.scm"); + ifstream is("store-script-test.scm"); ostringstream os; scheme::setupDisplay(os); scheme::Env globalEnv = scheme::setupEnvironment(pool); @@ -66,7 +66,7 @@ bool testEval() { { gc_scoped_pool pool; - ifstream is("store-script.scm"); + ifstream is("store-script-test.scm"); ostringstream os; scheme::setupDisplay(os); diff --git a/sca-cpp/trunk/test/store-script/store-script.scm b/sca-cpp/trunk/test/store-script/store-script-test.scm index 30c10d8184..30c10d8184 100644 --- a/sca-cpp/trunk/test/store-script/store-script.scm +++ b/sca-cpp/trunk/test/store-script/store-script-test.scm diff --git a/sca-cpp/trunk/test/store-script/store.scm b/sca-cpp/trunk/test/store-script/store.scm index 01f72d0bea..e325a65d74 100644 --- a/sca-cpp/trunk/test/store-script/store.scm +++ b/sca-cpp/trunk/test/store-script/store.scm @@ -20,6 +20,10 @@ (shoppingCart "gettotal") ) +(define (deleteall catalog shoppingCart shoppingTotal) + (shoppingCart "deleteall") +) + (define (delete id catalog shoppingCart shoppingTotal) (shoppingCart "delete" id) ) |