diff --git a/README.md b/README.md index c980698..a572d76 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,22 @@ -Aloha, funky time! - curl -i http://localhost:8080/transactions curl -i http://localhost:8080/transactions/1 curl -i -X POST -H "Content-Type:application/json" -d '{"account":"http://localhost:8080/accounts/1","amount":12.3,"date":"2016-05-31T22:00:00.000+0000","description":"test","category":"http://localhost:8080/categories/1"}' http://localhost:8080/transactions +curl --user adam@mail.com:test -i -X DELETE http://localhost:8080/transactions/4 -https://letsencrypt.org/getting-started/ \ No newline at end of file + + + +https://letsencrypt.org/getting-started/ + + + +# TODO +- Auslagen und Entnahmen aufsummieren und anzeigen +- 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/SpringDataRestCustomization.java b/src/main/java/de/tilman/transactions/SpringDataRestCustomization.java index 6c1cc2a..230157e 100644 --- a/src/main/java/de/tilman/transactions/SpringDataRestCustomization.java +++ b/src/main/java/de/tilman/transactions/SpringDataRestCustomization.java @@ -8,6 +8,7 @@ import de.tilman.transactions.domain.Account; import de.tilman.transactions.domain.Category; import de.tilman.transactions.domain.Transaction; import de.tilman.transactions.domain.User; +import de.tilman.transactions.domain.Withdrawal; @Component public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter { @@ -16,6 +17,6 @@ public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { - config.exposeIdsFor(Account.class, Category.class, Transaction.class, User.class); + config.exposeIdsFor(Account.class, Category.class, Transaction.class, User.class, Withdrawal.class); } } diff --git a/src/main/java/de/tilman/transactions/domain/Account.java b/src/main/java/de/tilman/transactions/domain/Account.java index a7ecafd..dc0f08d 100644 --- a/src/main/java/de/tilman/transactions/domain/Account.java +++ b/src/main/java/de/tilman/transactions/domain/Account.java @@ -33,9 +33,6 @@ public class Account { @OneToMany(mappedBy = "account") private List withdrawals; -// @ElementCollection -// private Map withdrawals = new Hashtable(); - public Long getId() { @@ -81,13 +78,5 @@ public class Account { public void setWithdrawals(List withdrawals) { this.withdrawals = withdrawals; } - -// public Map getWithdrawals() { -// return withdrawals; -// } -// -// public void setWithdrawals(Map withdrawals) { -// this.withdrawals = withdrawals; -// } } diff --git a/src/main/java/de/tilman/transactions/repository/TransactionRepository.java b/src/main/java/de/tilman/transactions/repository/TransactionRepository.java index f30f744..c1f624b 100644 --- a/src/main/java/de/tilman/transactions/repository/TransactionRepository.java +++ b/src/main/java/de/tilman/transactions/repository/TransactionRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RestResource; -import org.springframework.security.access.prepost.PreAuthorize; import de.tilman.transactions.domain.Transaction; @@ -30,5 +29,9 @@ public interface TransactionRepository extends PagingAndSortingRepository getDescriptionsByAccount(@Param("accountId") Long accountId, @Param("prefix") String prefix, Pageable pageable); - + + @RestResource(path = "outstandings") + @Query("SELECT t FROM Transaction t INNER JOIN t.account a WHERE a.id = :accountId AND t.creditor.id = :userId ORDER BY t.date DESC") + Page getTransactionsForCreditorByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable); + } diff --git a/src/main/java/de/tilman/transactions/repository/WithdrawalRepository.java b/src/main/java/de/tilman/transactions/repository/WithdrawalRepository.java index ef5c67d..6aa9b92 100644 --- a/src/main/java/de/tilman/transactions/repository/WithdrawalRepository.java +++ b/src/main/java/de/tilman/transactions/repository/WithdrawalRepository.java @@ -1,9 +1,18 @@ package de.tilman.transactions.repository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RestResource; import de.tilman.transactions.domain.Withdrawal; public interface WithdrawalRepository extends PagingAndSortingRepository { + + @RestResource(path = "forAccount") + @Query("SELECT w FROM Withdrawal w INNER JOIN w.account a WHERE a.id = :accountId AND w.user.id = :userId ORDER BY t.date DESC") + Page getWithdrawalsForUserByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable); } diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 67b975a..f60826b 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -1,6 +1,6 @@ var transactionControllers = angular.module('transactionControllers', ['ngResource']); -transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', function($scope, $location, $resource) { +transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', function($scope, $location, $resource, $q) { $scope.refreshList = function() { @@ -23,7 +23,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' // get recent transactions var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get(); - transactions.$promise.then(function(data) { $scope.transactions = transactions._embedded.transactions; @@ -37,6 +36,25 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' var accountUsers = $resource($scope.account._links.users.href).get(); accountUsers.$promise.then(function(data) { $scope.accountUsers = accountUsers._embedded.users; + + // get outstandings for all users of the account + var promises = new Array($scope.accountUsers.length); + for (i = 0; i < $scope.accountUsers.length; i++) { + var resource = $resource('/transactions/search/outstandings', { accountId: $scope.account.id, userId: $scope.accountUsers[i].id }).get(); + promises[i] = resource.$promise; + } + + $q.all(promises).then(function(data) { + for (i = 0; i < data.length; i++) { + var outstandingSum = 0; + for (j = 0; j < data[i]._embedded.transactions.length; j++) { + outstandingSum = outstandingSum + data[i]._embedded.transactions[j].amount; + } + $scope.accountUsers[i].outstandings = outstandingSum; + console.log('$scope.userinfo.outstandings: ' + $scope.accountUsers[i].outstandings); + } + }); + }); } diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/partials/transaction-list.html index 526ad56..cf33ec0 100644 --- a/src/main/resources/static/partials/transaction-list.html +++ b/src/main/resources/static/partials/transaction-list.html @@ -57,6 +57,10 @@ {{transaction.description}} + +
+ {{user.name}} {{user.outstandings}} €
+