Solian/lib/models/relations.dart

58 lines
1.4 KiB
Dart
Raw Normal View History

2024-05-18 10:17:16 +00:00
import 'package:solian/models/account.dart';
2024-07-23 17:17:41 +00:00
class Relationship {
2024-05-18 10:17:16 +00:00
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
int accountId;
int relatedId;
Account account;
Account related;
int status;
2024-07-23 17:17:41 +00:00
Relationship({
2024-05-18 10:17:16 +00:00
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.accountId,
required this.relatedId,
required this.account,
required this.related,
required this.status,
});
2024-07-23 17:17:41 +00:00
factory Relationship.fromJson(Map<String, dynamic> json) => Relationship(
2024-05-18 10:17:16 +00:00
id: json['id'],
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'],
accountId: json['account_id'],
relatedId: json['related_id'],
account: Account.fromJson(json['account']),
related: Account.fromJson(json['related']),
status: json['status'],
);
Map<String, dynamic> toJson() => {
'id': id,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'account_id': accountId,
'related_id': relatedId,
'account': account.toJson(),
'related': related.toJson(),
'status': status,
};
Account getOtherside(int selfId) {
if (accountId != selfId) {
return account;
} else {
return related;
}
}
}