basic csv loader, transaction list & half done stats page
This commit is contained in:
21
lib/repositories/account/models/account.dart
Normal file
21
lib/repositories/account/models/account.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'transaction.dart';
|
||||
|
||||
class Account {
|
||||
List<Transaction> transactions;
|
||||
|
||||
Account({
|
||||
this.transactions = const [],
|
||||
});
|
||||
|
||||
factory Account.fromJson(Map<String, dynamic> json) {
|
||||
return Account(
|
||||
transactions: (jsonDecode(json['transactions']) as List<dynamic>).map((transaction) => Transaction.fromJson(transaction)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {
|
||||
'transactions': jsonEncode(transactions.map((transaction) => transaction.toJson()).toList()),
|
||||
};
|
||||
}
|
||||
33
lib/repositories/account/models/transaction.dart
Normal file
33
lib/repositories/account/models/transaction.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
class Transaction {
|
||||
DateTime date;
|
||||
String category;
|
||||
String description;
|
||||
String account;
|
||||
double value;
|
||||
|
||||
Transaction({
|
||||
required this.date,
|
||||
required this.category,
|
||||
required this.description,
|
||||
required this.account,
|
||||
required this.value
|
||||
});
|
||||
|
||||
factory Transaction.fromJson(Map<String, dynamic> json) {
|
||||
return Transaction(
|
||||
date: DateTime.parse(json['date']),
|
||||
category: json['category'],
|
||||
description: json['description'],
|
||||
account: json['account'],
|
||||
value: double.parse(json['value']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {
|
||||
'date': date.toIso8601String(),
|
||||
'category': category,
|
||||
'description': description,
|
||||
'account': account,
|
||||
'value': value.toString(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user