Browse files

added implementation of POST to _all_docs

contributed by Sameer Segal
  • Loading branch information...
1 parent ebffc8a commit 1dd6cc4353665713555ea8a80564be812c4cee0e @mschoch mschoch committed Aug 7, 2012
Showing with 23 additions and 2 deletions.
  1. +23 −2 TouchDB-Android/src/com/couchbase/touchdb/router/TDRouter.java
View
25 TouchDB-Android/src/com/couchbase/touchdb/router/TDRouter.java
@@ -687,8 +687,29 @@ public TDStatus do_GET_Document_all_docs(TDDatabase _db, String _docID, String _
}
public TDStatus do_POST_Document_all_docs(TDDatabase _db, String _docID, String _attachmentName) {
- //FIXME implement
- throw new UnsupportedOperationException();
+ TDQueryOptions options = new TDQueryOptions();
+ if (!getQueryOptions(options)) {
+ return new TDStatus(TDStatus.BAD_REQUEST);
+ }
+
+ Map<String, Object> body = getBodyAsDictionary();
+ if (body == null) {
+ return new TDStatus(TDStatus.BAD_REQUEST);
+ }
+
+ Map<String, Object> result = null;
+ if (body.containsKey("keys") && body.get("keys") instanceof ArrayList) {
+ ArrayList<String> keys = (ArrayList<String>) body.get("keys");
+ result = db.getDocsWithIDs(keys, options);
+ } else {
+ result = db.getAllDocs(options);
+ }
+
+ if (result == null) {
+ return new TDStatus(TDStatus.INTERNAL_SERVER_ERROR);
+ }
+ connection.setResponseBody(new TDBody(result));
+ return new TDStatus(TDStatus.OK);
}
public TDStatus do_POST_Document_bulk_docs(TDDatabase _db, String _docID, String _attachmentName) {

0 comments on commit 1dd6cc4

Please sign in to comment.