getUserNotes function

Future<Map<String, dynamic>> getUserNotes(
  1. String userName,
  2. String server,
  3. String apiBase,
  4. String baseUrl,
)

Attempts to retrieve the notes a user has created on the supplied instance as a map. If this fails, an error map is returned.

Implementation

Future<Map<String,dynamic>> getUserNotes(
    String userName,
    String server,
    String apiBase,
    String baseUrl
) async {
    Map<String,dynamic> userInfo = await getUserInfo(
        userName,
        server,
        baseUrl,
        apiBase
    );
    String userId = '';
  if (userInfo.containsKey('result')){
    Map<String,dynamic> targetUserInfo = userInfo["result"];
    if (targetUserInfo.containsKey('id')){
      userId = targetUserInfo['id'];
    }
    else {
      Map<String,dynamic> errMap = new Map();
      errMap["error"] = "Could not retrieve user ID!";
      return errMap;
    }
  }
  else {
    Map<String,dynamic> errMap = new Map();
      errMap["error"] = "Error response received for retrieving user ID!";
      return errMap;
  }
  String reqUrl = '$baseUrl$apiBase/users/notes';
  Map<String,dynamic> headers = new Map();
  headers['Content-Type'] = 'application/json';
  Map<String,dynamic> payload = new Map();
  payload['userId'] = userId;
  Map<String,dynamic> postRequest = await fetchJSON(
    'POST',
    headers,
    payload,
    reqUrl
  );
  return postRequest;
}