55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
Dart
class Post {
|
|
final String id;
|
|
final String body;
|
|
final String userId;
|
|
final String username;
|
|
final String displayName;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
|
|
Post({
|
|
required this.id,
|
|
required this.body,
|
|
required this.userId,
|
|
required this.username,
|
|
required this.displayName,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
});
|
|
|
|
factory Post.fromJson(Map<String, dynamic> json) {
|
|
return Post(
|
|
id: json['id'] ?? '',
|
|
body: json['body'] ?? '',
|
|
userId: json['userId'] ?? '',
|
|
username: json['username'] ?? '',
|
|
displayName: json['displayName'] ?? '',
|
|
createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toIso8601String()),
|
|
updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toIso8601String()),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'body': body,
|
|
'userId': userId,
|
|
'username': username,
|
|
'displayName': displayName,
|
|
'createdAt': createdAt.toIso8601String(),
|
|
'updatedAt': updatedAt.toIso8601String(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class CreatePostRequest {
|
|
final String body;
|
|
|
|
CreatePostRequest({required this.body});
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'body': body,
|
|
};
|
|
}
|
|
} |