diff --git a/CHANGELOG.md b/CHANGELOG.md index 40028e1..9253d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Added `Restrr` methods: `createAccount`, `getAccounts`, `retrieveAccountById`, `retrieveAllAccounts` - Added `Transaction` - Added `TransactionRoutes` - - Added `Transaction` methods: `delete`, `update` + - Added `Transaction` methods: `delete`, `update`, `getSourceAccount`, `getDestinationAccount`, `retrieveSourceAccount`, `retrieveDestinationAccount` - Added `Restrr` methods: `createTransaction`, `retrieveTransactionById`, `retrieveAllTransactions` - Added `Restrr#getCurrencies` - Fixed `Session#delete` using a wrong route diff --git a/lib/src/api/entities/transaction/transaction.dart b/lib/src/api/entities/transaction/transaction.dart index bd94c57..a80e705 100644 --- a/lib/src/api/entities/transaction/transaction.dart +++ b/lib/src/api/entities/transaction/transaction.dart @@ -23,4 +23,12 @@ abstract class Transaction extends RestrrEntity { Id? budget, DateTime? executedAt, }); + + Account? getSourceAccount(); + + Future? retrieveSourceAccount({bool forceRetrieve = false}); + + Account? getDestinationAccount(); + + Future? retrieveDestinationAccount({bool forceRetrieve = false}); } diff --git a/lib/src/internal/entities/transaction_impl.dart b/lib/src/internal/entities/transaction_impl.dart index 29141da..76ce915 100644 --- a/lib/src/internal/entities/transaction_impl.dart +++ b/lib/src/internal/entities/transaction_impl.dart @@ -84,4 +84,26 @@ class TransactionImpl extends RestrrEntityImpl implements Transaction { }); return response.data!; } + + @override + Account? getSourceAccount() => source == null ? null : api.accountCache.get(source!); + + @override + Future? retrieveSourceAccount({bool forceRetrieve = false}) { + if (source == null) { + return null; + } + return api.retrieveAccountById(source!, forceRetrieve: forceRetrieve); + } + + @override + Account? getDestinationAccount() => destination == null ? null : api.accountCache.get(destination!); + + @override + Future? retrieveDestinationAccount({bool forceRetrieve = false}) { + if (destination == null) { + return null; + } + return api.retrieveAccountById(destination!, forceRetrieve: forceRetrieve); + } }