fetchPostComments method

Future<List<PostCommentModel>> fetchPostComments(
  1. dynamic postId
)

Implementation

Future<List<PostCommentModel>> fetchPostComments(postId) async {
  Log(
    logName: 'FetchPostComments',
    className: 'Comment',
    methodName: 'fetchPostComments',
    type: 'INFO',
    text:
        '{event: Fetch Post Comments, user: ${currentUser?.userPayloadId}, user is ${currentUser?.firstName} ${currentUser?.lastName}, post id: $postId',
  );
  return _httpService.fetchCommentsByPostId(postId).then((data) async {
    if (data.statusCode == 200) {
      List<dynamic> comments = json.decode(data.body);
      List<PostCommentModel> commentsList =
          comments.map((i) => PostCommentModel.fromJson(i)).toList();
      return commentsList;
    } else {
      return List<PostCommentModel>.from([]);
    }
  });
}