basic csv loader, transaction list & half done stats page

This commit is contained in:
2024-02-04 22:34:28 +01:00
commit 3abee9ff6f
179 changed files with 6999 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import 'dart:convert';
import 'package:rxdart/subjects.dart';
import 'package:tunas/clients/storage/storage_client.dart';
import 'package:tunas/repositories/account/models/account.dart';
import 'package:tunas/repositories/account/models/transaction.dart';
class AccountRepository {
String accountFile = 'main_account.json';
final StorageClient _storageClient;
final _transactionsController = BehaviorSubject<List<Transaction>>.seeded(const []);
AccountRepository({
required storageClient,
}) : _storageClient = storageClient {
init();
}
init() async {
final account = await getAccount();
_transactionsController.add(account.transactions);
}
Stream<List<Transaction>> getTransactionsStream() {
return _transactionsController.asBroadcastStream();
}
Future<Account> getAccount() async {
String json = await _storageClient.load(accountFile);
Map<String, dynamic> accountJson = jsonDecode(json);
return Account.fromJson(accountJson);
}
saveAccount(Account account) async {
await _storageClient.save(accountFile, jsonEncode(account.toJson()));
}
saveTransactions(List<Transaction> transactions) async {
final account = Account(transactions: transactions);
await saveAccount(account);
_transactionsController.add(account.transactions);
}
}