fetchPostsByUserId method

Future<List<PostModel>> fetchPostsByUserId(
  1. dynamic id
)

Implementation

Future<List<PostModel>> fetchPostsByUserId(id) async {
  Log(
    logName: 'FetchPostsByUserId',
    className: 'Post',
    methodName: 'fetchPostsByUserId',
    type: 'INFO',
    text:
        '{event: Fetch Posts By User Id, user: ${currentUser?.userPayloadId}, user is ${currentUser?.firstName} ${currentUser?.lastName}, user id: $id',
  );
  return _httpService.fetchPostsByUserId(id).then((data) async {
    if (data.statusCode == 200) {
      List<dynamic> posts = json.decode(data.body);
      List<PostModel> postsList =
          posts.map((i) => PostModel.fromJson(i)).toList();
      return postsList;
    } else {
      return List<PostModel>.from([]);
    }
  });
}