documentsByQuery method
Get a list documents from a query.
The query string uses the RSQL query language for RESTful APIs.
See the RSQL Documentation.
Implementation
Future<List<DocumentSnapshot>> documentsByQuery(String query) async {
// GET the list of documents in this collection from the CARP web service
http.Response response = await httpr.get(
Uri.encodeFull('$documentEndpointUri?query=$query'),
headers: headers);
int httpStatusCode = response.statusCode;
if (httpStatusCode == HttpStatus.ok) {
List<dynamic> documentsJson = json.decode(response.body);
List<DocumentSnapshot> documents = [];
for (var item in documentsJson) {
Map<String, dynamic> documentJson = item;
String key = documentJson["name"];
documents.add(DocumentSnapshot._("$key", documentJson));
}
return documents;
}
// All other cases are treated as an error.
Map<String, dynamic> responseJson = json.decode(response.body);
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson["message"],
path: responseJson["path"],
);
}