documents method
Get all documents for this study.
Can only be accessed by users who are authenticated as researchers.
Note that this might return a very long list of documents and the request may time out.
Implementation
Future<List<DocumentSnapshot>> documents() async {
http.Response response =
await httpr.get(Uri.encodeFull(documentEndpointUri), headers: headers);
int httpStatusCode = response.statusCode;
if (httpStatusCode == HttpStatus.ok) {
List<dynamic> documentsJson = json.decode(response.body) as List<dynamic>;
List<DocumentSnapshot> documents = [];
for (var item in documentsJson) {
Map<String, dynamic> documentJson = item as Map<String, dynamic>;
String key = documentJson["name"].toString();
documents.add(DocumentSnapshot._(key, documentJson));
}
return documents;
}
// All other cases are treated as an error.
Map<String, dynamic> responseJson =
json.decode(response.body) as Map<String, dynamic>;
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson["message"].toString(),
path: responseJson["path"].toString(),
);
}