outing_log_comment.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. class OutingLogComment {
  2. final String id;
  3. final String logId;
  4. final String commenterId;
  5. final String commenterName;
  6. final String commenterPosition;
  7. final int ratingStars;
  8. final String commentText;
  9. final DateTime createTime;
  10. const OutingLogComment({
  11. required this.id,
  12. this.logId = '',
  13. this.commenterId = '',
  14. this.commenterName = '',
  15. this.commenterPosition = '',
  16. this.ratingStars = 5,
  17. required this.commentText,
  18. required this.createTime,
  19. });
  20. factory OutingLogComment.fromJson(Map<String, dynamic> json) {
  21. return OutingLogComment(
  22. id: json['id'] as String,
  23. logId: json['logId'] as String? ?? '',
  24. commenterId: json['commenterId'] as String? ?? '',
  25. commenterName: json['commenterName'] as String? ?? '',
  26. commenterPosition: json['commenterPosition'] as String? ?? '',
  27. ratingStars: json['ratingStars'] as int? ?? 5,
  28. commentText: json['commentText'] as String? ?? '',
  29. createTime: DateTime.parse(json['createTime'] as String),
  30. );
  31. }
  32. Map<String, dynamic> toJson() => {
  33. 'id': id,
  34. 'logId': logId,
  35. 'commenterId': commenterId,
  36. 'commenterName': commenterName,
  37. 'commenterPosition': commenterPosition,
  38. 'ratingStars': ratingStars,
  39. 'commentText': commentText,
  40. 'createTime': createTime.toIso8601String(),
  41. };
  42. }