Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Implemented Transaction#getSourceAccount, `Transaction#getDestinati…
Browse files Browse the repository at this point in the history
…onAccount`, `Transaction#retrieveSourceAccount` & `Transaction#retrieveDestinationAccount`
  • Loading branch information
jasonlessenich committed Mar 24, 2024
1 parent 02c8496 commit 34f5ec7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/src/api/entities/transaction/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ abstract class Transaction extends RestrrEntity {
Id? budget,
DateTime? executedAt,
});

Account? getSourceAccount();

Future<Account>? retrieveSourceAccount({bool forceRetrieve = false});

Account? getDestinationAccount();

Future<Account>? retrieveDestinationAccount({bool forceRetrieve = false});
}
22 changes: 22 additions & 0 deletions lib/src/internal/entities/transaction_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Account>? 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<Account>? retrieveDestinationAccount({bool forceRetrieve = false}) {
if (destination == null) {
return null;
}
return api.retrieveAccountById(destination!, forceRetrieve: forceRetrieve);
}
}

0 comments on commit 34f5ec7

Please sign in to comment.