sum of expenses
This commit is contained in:
@@ -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/
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ public class Account {
|
||||
@OneToMany(mappedBy = "account")
|
||||
private List<Withdrawal> withdrawals;
|
||||
|
||||
// @ElementCollection
|
||||
// private Map<User, BigDecimal> withdrawals = new Hashtable<User, BigDecimal>();
|
||||
|
||||
|
||||
|
||||
public Long getId() {
|
||||
@@ -81,13 +78,5 @@ public class Account {
|
||||
public void setWithdrawals(List<Withdrawal> withdrawals) {
|
||||
this.withdrawals = withdrawals;
|
||||
}
|
||||
|
||||
// public Map<User, BigDecimal> getWithdrawals() {
|
||||
// return withdrawals;
|
||||
// }
|
||||
//
|
||||
// public void setWithdrawals(Map<User, BigDecimal> withdrawals) {
|
||||
// this.withdrawals = withdrawals;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Transa
|
||||
@RestResource(path = "descriptions")
|
||||
@Query("SELECT t FROM Transaction t INNER JOIN t.account a WHERE a.id = :accountId AND t.description LIKE :prefix% ORDER BY t.date DESC")
|
||||
Page<Transaction> 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<Transaction> getTransactionsForCreditorByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Withdrawal, Long> {
|
||||
|
||||
@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<Withdrawal> getWithdrawalsForUserByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable);
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@
|
||||
<td>{{transaction.description}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div style="margin: auto; width: 30 em; text-align: center;">
|
||||
<span ng-repeat="user in accountUsers">{{user.name}} {{user.outstandings}} €<br/></span>
|
||||
</div>
|
||||
|
||||
<!-- div>
|
||||
<pre style="font-size: 75%; color: darkgray;">{{account | json}}</pre>
|
||||
|
||||
Reference in New Issue
Block a user