Files
food_hub_app/lib/models/moment.dart
2025-11-23 00:02:41 +08:00

83 lines
1.6 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
part 'moment.g.dart';
@JsonSerializable()
class Comment {
int id;
String username;
String avatar;
String content;
String date;
Comment({
required this.id,
required this.username,
required this.avatar,
required this.content,
required this.date,
});
factory Comment.fromJson(Map<String, dynamic> json) => _$CommentFromJson(json);
Map<String, dynamic> toJson() => _$CommentToJson(this);
}
@JsonSerializable()
class Moment {
int? id;
int? userId;
String? username;
String? avatar;
String content;
List<String> imageList;
String? date;
List<int>? likeList;
List<Comment>? commentList;
Moment({
this.id,
this.userId,
this.username,
this.avatar,
required this.content,
required this.imageList,
this.date,
this.likeList,
this.commentList,
});
factory Moment.fromJson(Map<String, dynamic> json) => _$MomentFromJson(json);
Map<String, dynamic> toJson() => _$MomentToJson(this);
static Moment getEmpty() {
return Moment(
id: 0,
content: '',
imageList: []
);
}
}
@JsonSerializable()
class PageMoment {
final List<Moment> records;
final int total;
final int size;
final int current;
final int pages;
PageMoment({
required this.records,
required this.total,
required this.size,
required this.current,
required this.pages,
});
factory PageMoment.fromJson(Map<String, dynamic> json) => _$PageMomentFromJson(json);
Map<String, dynamic> toJson() => _$PageMomentToJson(this);
}