33 lines
1.1 KiB
Dart
33 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:tunas/repositories/account/models/budget.dart';
|
|
import 'package:tunas/repositories/account/models/category.dart';
|
|
|
|
import 'transaction.dart';
|
|
|
|
class Account {
|
|
List<Transaction> transactions;
|
|
List<Budget> budgets;
|
|
List<Category> categories;
|
|
|
|
Account({
|
|
this.transactions = const [],
|
|
this.budgets = const [],
|
|
this.categories = const [],
|
|
});
|
|
|
|
factory Account.fromJson(Map<String, dynamic> json) {
|
|
return Account(
|
|
transactions: (jsonDecode(json['transactions']) as List<dynamic>).map((transaction) => Transaction.fromJson(transaction)).toList(),
|
|
budgets: (jsonDecode(json['budgets']) as List<dynamic>).map((budget) => Budget.fromJson(budget)).toList(),
|
|
categories: (jsonDecode(json['categories']) as List<dynamic>).map((category) => Category.fromJson(category)).toList(),
|
|
);
|
|
}
|
|
|
|
Map<String, String> toJson() => {
|
|
'transactions': jsonEncode(transactions.map((transaction) => transaction.toJson()).toList()),
|
|
'budgets': jsonEncode(budgets.map((budget) => budget.toJson()).toList()),
|
|
'categories': jsonEncode(categories.map((category) => category.toJson()).toList()),
|
|
};
|
|
}
|