queryFiles method
Returns file objects in the study based on a query
.
studyId
can be omitted if specified as part of this service's study.
If query
is omitted, all file objects are returned.
Implementation
Future<List<CarpFileResponse>> queryFiles(
String? query, {
String? studyId,
}) async {
final String url = (query != null)
? "${getFileEndpointUri(studyId)}?query=$query"
: getFileEndpointUri(studyId);
http.Response response =
await httpr.get(Uri.encodeFull(url), headers: headers);
int httpStatusCode = response.statusCode;
switch (httpStatusCode) {
case HttpStatus.ok:
{
List<dynamic> list = json.decode(response.body) as List<dynamic>;
List<CarpFileResponse> fileList = [];
for (var element in list) {
fileList.add(CarpFileResponse._(element as Map<String, dynamic>));
}
return fileList;
}
default:
// All other cases are treated as an error.
{
Map<String, dynamic> responseJson =
json.decode(response.body) as Map<String, dynamic>;
throw CarpServiceException.fromMap(httpStatusCode, responseJson);
}
}
}