Solian/lib/models/account.dart

105 lines
2.8 KiB
Dart
Raw Normal View History

2024-05-18 10:17:16 +00:00
class Account {
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
String name;
String nick;
dynamic avatar;
dynamic banner;
2024-05-18 10:17:16 +00:00
String description;
2024-06-03 15:36:46 +00:00
List<AccountBadge>? badges;
2024-05-18 10:17:16 +00:00
String? emailAddress;
int? externalId;
Account({
required this.id,
required this.createdAt,
required this.updatedAt,
2024-05-28 16:14:41 +00:00
required this.deletedAt,
2024-05-18 10:17:16 +00:00
required this.name,
required this.nick,
required this.avatar,
required this.banner,
required this.description,
2024-06-03 15:36:46 +00:00
required this.badges,
2024-05-28 16:14:41 +00:00
required this.emailAddress,
2024-05-18 10:17:16 +00:00
this.externalId,
});
factory Account.fromJson(Map<String, dynamic> json) => Account(
id: json['id'],
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'],
name: json['name'],
nick: json['nick'],
avatar: json['avatar'],
banner: json['banner'],
description: json['description'],
emailAddress: json['email_address'],
2024-06-03 15:36:46 +00:00
badges: json['badges']
?.map((e) => AccountBadge.fromJson(e))
.toList()
.cast<AccountBadge>(),
2024-05-18 10:17:16 +00:00
externalId: json['external_id'],
);
Map<String, dynamic> toJson() => {
'id': id,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'name': name,
'nick': nick,
'avatar': avatar,
'banner': banner,
'description': description,
'email_address': emailAddress,
2024-06-03 15:36:46 +00:00
'badges': badges?.map((e) => e.toJson()).toList(),
2024-05-18 10:17:16 +00:00
'external_id': externalId,
};
}
2024-06-03 15:36:46 +00:00
class AccountBadge {
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
Map<String, dynamic>? metadata;
String type;
int accountId;
AccountBadge({
required this.id,
required this.accountId,
required this.createdAt,
required this.updatedAt,
required this.deletedAt,
required this.metadata,
required this.type,
});
factory AccountBadge.fromJson(Map<String, dynamic> json) => AccountBadge(
id: json["id"],
accountId: json["account_id"],
updatedAt: DateTime.parse(json["updated_at"]),
createdAt: DateTime.parse(json["created_at"]),
deletedAt: json["deleted_at"] != null
? DateTime.parse(json["deleted_at"])
: null,
metadata: json["metadata"],
type: json["type"],
);
Map<String, dynamic> toJson() => {
"id": id,
"account_id": accountId,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt?.toIso8601String(),
"metadata": metadata,
"type": type,
};
}