addPost method

Future<PostModel?> addPost({
  1. required dynamic user,
  2. dynamic title,
  3. dynamic description,
  4. dynamic type,
  5. dynamic attachedUrl,
  6. dynamic pollQuestionId,
})

Implementation

Future<PostModel?> addPost(
    {required user, title, description, type, attachedUrl, pollQuestionId}) {
  Log(
    logName: 'AddPost',
    className: 'Post',
    methodName: 'addPost',
    type: 'INFO',
    text:
        '{event: Add Post, user: ${currentUser?.userPayloadId}, user is ${currentUser?.firstName} ${currentUser?.lastName}, user id: ${user.id}, title: $title, description: $description, type: $type, attachedUrl: $attachedUrl, poll question id: $pollQuestionId',
  );
  return _httpService
      .addPost(
          user: user,
          description: description,
          type: type,
          attachedUrl: attachedUrl,
          title: title,
          pollQuestionId: pollQuestionId)
      .then((data) async {
    if (data.statusCode >= 200 && data.statusCode < 300) {
      List<dynamic> res = json.decode(data.body);
      List<PostModel> postData =
          res.map((i) => PostModel.fromJson(i)).toList();
      if (postData[0] != null) return postData[0];

      return null;
    }
    return null;
  });
}