diff --git a/README.md b/README.md index 52b3fdf..f13ca93 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,19 @@ curl --user adam@mail.com:test -i -X DELETE http://localhost:8080/transactions/4 https://letsencrypt.org/getting-started/ -http://localhost:8080/transactions?size=10&sort=date,desc - - -# TODO +- http://localhost:8080/transactions?size=10&sort=date,desc - alles über findAll filtern http://stackoverflow.com/questions/33018127/spring-data-rest-sort-by-multiple-properties - account direkt in Transaction anzeigen http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.excerpting-commonly-accessed-data --> mit neuer Projektion: keine zusätzlichen GET-Requests für Creditor und Category, account per Parameter filtern (wie getDescriptionsByAccount), findFirst10 kann entfernt werden + + + +# TODO - Transaktionen in Popup editieren/löschen als Admin -- Liste von Transaktionen anzeigen -- CSV-Export -- Verschlüsselung aktivieren - Autocomplete für Notizfeld -- Auslagen zurücksetzen +- Admin-Bereich + - Auslagen zurücksetzen + - (beliebig lange) Liste von Transaktionen anzeigen + - CSV-Export +- Verschlüsselung aktivieren - Absicherung: DELETE darf von Usern nur auf die letzte Transaktion angewendet werden diff --git a/src/main/java/de/tilman/transactions/repository/TransactionRepository.java b/src/main/java/de/tilman/transactions/repository/TransactionRepository.java index 1b70f39..2a2f230 100644 --- a/src/main/java/de/tilman/transactions/repository/TransactionRepository.java +++ b/src/main/java/de/tilman/transactions/repository/TransactionRepository.java @@ -22,9 +22,6 @@ public interface TransactionRepository extends PagingAndSortingRepository findFirst10ByAccountIdOrderByDateDescLastChangeDesc(@Param("accountId") Long accountId); - // TODO How to prevent loading transactions from other user's accounts? --> Solution? http://stackoverflow.com/a/21577081/3761783 // http://localhost:8080/transactions/search/descriptions?accountId=1&prefix=Kan // http://localhost:8080/transactions/search/descriptions?accountId=1&prefix=C&size=2 @@ -34,6 +31,10 @@ public interface TransactionRepository extends PagingAndSortingRepository getTransactionsForCreditorByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable); + List getTransactionsForCreditorByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId); + + // http://localhost:8080/transactions/search/forAccount?accountId=2&size=10&sort=date,desc + @RestResource(path = "forAccount") + Page findByAccountId(@Param("accountId") Long accountId, Pageable pageable); } diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql index ee24579..6c15bed 100644 --- a/src/main/resources/data-h2.sql +++ b/src/main/resources/data-h2.sql @@ -1,17 +1,17 @@ INSERT INTO User (id, name, username) VALUES (1, 'Adam', 'adam@mail.com'), (2, 'Betty', 'betty@mail.com'); INSERT INTO Account (id, name, owner_id) VALUES (1, 'Gemeinschaftskonto', 1), (2, 'Konto Adam', 1); -INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (1, 1, 20.00, 2, '2015-06-12'); -INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (2, 1, 10.00, 1, '2015-06-14'); +INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (1, 1, 20.00, 2, '2015-06-12 18:20:15'); +INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (2, 1, 10.00, 1, '2015-06-14 10:03:00'); INSERT INTO Category (id, name, account_id, position) VALUES (1, 'Essen - Lebensmittel', 1, 2), (2, 'Einnahmen - Gehalt', 1, 1), (3, 'Essen - Arbeit', 1, 3), (4, 'Einnahmen - Gehalt', 2, 1), (5, 'Technik - Server und Hosting', 2, 2); INSERT INTO Account_User (account_id, user_id) VALUES (1, 1), (1, 2), (2, 1); INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES - (NULL, 1280.81, 1, 1, '2015-06-01', 'Gehalt', null), - (NULL, -2.21, 1, 2, '2015-06-10', 'Brot', null), - (NULL, -3.41, 1, 2, '2015-06-12', 'Gemüse', null), + (NULL, 1280.81, 1, 2, '2015-06-01 14:14:14', 'Gehalt', null), + (NULL, -2.21, 1, 1, '2015-06-10', 'Brot', null), + (NULL, -3.41, 1, 1, '2015-06-12', 'Gemüse', null), (NULL, -7.81, 1, 3, '2015-06-19', 'Kantine', null), (NULL, -4.81, 1, 3, '2015-06-18', 'Currywurst', 1), (NULL, -4.50, 1, 3, '2015-06-19', 'Currywurst', null), @@ -26,34 +26,34 @@ INSERT INTO Transaction (id, amount, account_id, category_id, date, description, -- add as many transactions as needed -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction01', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction01', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction02', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction03', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction03', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction04', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction05', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction05', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction06', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction07', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction07', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction08', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction09', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction09', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction10', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction11', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction11', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction12', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction13', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction13', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction14', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction15', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction15', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction16', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction17', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction17', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction18', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction19', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction19', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction20', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction21', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction21', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction22', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction23', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction23', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction24', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction25', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction25', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction26', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction27', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction27', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction28', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction29', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2015-06-10', 'Transaction29', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction30', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.50, 1, 4, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit; diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index a5678e6..6c20b76 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -22,16 +22,12 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' } // get recent transactions - var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get(); - //var transactions = $resource('/transactions?size=10&sort=date,desc') + var transactions = $resource('http://localhost:8080/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc' }).get(); transactions.$promise.then(function(data) { $scope.transactions = transactions._embedded.transactions; - - for (var i = 0; i < $scope.transactions.length; i++) { - $scope.transactions[i].category = $resource($scope.transactions[i]._links.category.href).get(); - $scope.transactions[i].creditor = $resource($scope.transactions[i]._links.creditor.href).get(); - } - + $scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1); + $scope.prevPageAvailable = (transactions.page.number > 0); + $scope.pageNumber = transactions.page.number; }); var accountUsers = $resource($scope.account._links.users.href).get(); @@ -113,7 +109,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' $scope.initList = function() { console.log('initList()'); - $scope.transactionsPage = 0; + $scope.pageSize = 20; var userinfo = $resource('/user').get(); userinfo.$promise.then(function(data) { @@ -208,6 +204,18 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' $location.path('/transaction/' + transaction._links.self.href); }; + $scope.moreTransactions = function() { + if ($scope.nextPageAvailable) { + $scope.pageNumber++; + var transactions = $resource('http://localhost:8080/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc', page: $scope.pageNumber }).get(); + transactions.$promise.then(function(data) { + $scope.transactions = $scope.transactions.concat(transactions._embedded.transactions); + $scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1); + $scope.prevPageAvailable = (transactions.page.number > 0); + $scope.pageNumber = transactions.page.number; + }); + } + }; // initialize (http://stackoverflow.com/a/25662066/3761783) $scope.initList(); diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/partials/transaction-list.html index 1c38842..9538977 100644 --- a/src/main/resources/static/partials/transaction-list.html +++ b/src/main/resources/static/partials/transaction-list.html @@ -63,6 +63,9 @@ {{transaction.description}} +
+ more +
{{user.name}} {{user.outstandings | number : 2}} €