commentSearch method

Future<List<ApiComment>> commentSearch({
  1. String? userIdx,
  2. String? categoryIdx,
  3. bool? files,
  4. int limit = 20,
  5. int page = 1,
  6. String order = 'DESC',
})

코멘트 검색

categoryId is not supported. files 가 null 이면, 첨부 파일(사진)이 있던 없던 상관 없다. files 가 true 이면, 첨부 파일이 있는 코멘트만 가져온다. files 가 false 이면, 첨부 파일이 없는 코멘트만 가져온다.

Implementation

Future<List<ApiComment>> commentSearch({
  String? userIdx,
  String? categoryIdx,
  bool? files,
  int limit = 20,
  int page = 1,
  String order = 'DESC',
}) async {
  String where = "parentIdx > 0 AND deletedAt=0";
  if (userIdx != null) where += " AND userIdx=$userIdx";
  if (categoryIdx != null) where += " AND categoryIdx=$categoryIdx";
  if (files != null) {
    if (files)
      where += " AND files != ''";
    else
      where += " AND files == ''";
  }

  final Map<String, dynamic> data = {'route': 'comment.search', 'where': where, 'limit': limit, 'page': page};

  final jsonList = await request(data);

  List<ApiComment> _comments = [];
  for (int i = 0; i < jsonList.length; i++) {
    _comments.add(ApiComment.fromJson(jsonList[i]));
  }
  return _comments;
}