Withdrawals and deleteLastSubmission()
This commit is contained in:
@@ -27,8 +27,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers(HttpMethod.GET, "/public/**").permitAll()
|
.antMatchers(HttpMethod.GET, "/public/**").permitAll()
|
||||||
.anyRequest().authenticated();
|
.anyRequest().authenticated();
|
||||||
|
|
||||||
// http.httpBasic(); // XXX mit HTTP Basic Auth funktioniert der Logout nicht richtig
|
http.httpBasic(); // XXX mit HTTP Basic Auth funktioniert der Logout nicht richtig
|
||||||
http.formLogin();
|
// http.formLogin();
|
||||||
|
|
||||||
http.csrf().disable(); // XXX später wieder aktivieren
|
http.csrf().disable(); // XXX später wieder aktivieren
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package de.tilman.transactions.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.rest.webmvc.RepositoryRestController;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import de.tilman.transactions.domain.Transaction;
|
||||||
|
import de.tilman.transactions.repository.TransactionRepository;
|
||||||
|
|
||||||
|
//@RepositoryRestController
|
||||||
|
public class TransactionController {
|
||||||
|
|
||||||
|
// private final TransactionRepository repository;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// public TransactionController(TransactionRepository repository) {
|
||||||
|
// this.repository = repository;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RequestMapping(method = RequestMethod.DELETE, value = "/transactions/{id}")
|
||||||
|
// public @ResponseBody Iterable<Transaction> deleteTransaction() {
|
||||||
|
// Iterable<Transaction> producers = repository.findAll();
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // do some intermediate processing, logging, etc. with the producers
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// return producers; // or some filtered/altered/mapped version
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,6 +29,13 @@ public class Account {
|
|||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"))
|
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"))
|
||||||
private List<User> users;
|
private List<User> users;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "account")
|
||||||
|
private List<Withdrawal> withdrawals;
|
||||||
|
|
||||||
|
// @ElementCollection
|
||||||
|
// private Map<User, BigDecimal> withdrawals = new Hashtable<User, BigDecimal>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@@ -66,5 +73,21 @@ public class Account {
|
|||||||
public void setUsers(List<User> users) {
|
public void setUsers(List<User> users) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Withdrawal> getWithdrawals() {
|
||||||
|
return withdrawals;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package de.tilman.transactions.domain;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Withdrawal {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
private Account account;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
private BigDecimal amount;
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Account getAccount() {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccount(Account account) {
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmount(BigDecimal amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.data.rest.core.annotation.RestResource;
|
import org.springframework.data.rest.core.annotation.RestResource;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
import de.tilman.transactions.domain.Transaction;
|
import de.tilman.transactions.domain.Transaction;
|
||||||
|
|
||||||
@@ -15,6 +16,10 @@ public interface TransactionRepository extends PagingAndSortingRepository<Transa
|
|||||||
|
|
||||||
// @RestResource(exported = false)
|
// @RestResource(exported = false)
|
||||||
// Page<Transaction> findAll(Pageable pageable);
|
// Page<Transaction> findAll(Pageable pageable);
|
||||||
|
|
||||||
|
// @PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
// @Override
|
||||||
|
// void delete(Transaction transaction);
|
||||||
|
|
||||||
@RestResource(path = "last10")
|
@RestResource(path = "last10")
|
||||||
List<Transaction> findFirst10ByAccountIdOrderByDateDescLastChangeDesc(@Param("accountId") Long accountId);
|
List<Transaction> findFirst10ByAccountIdOrderByDateDescLastChangeDesc(@Param("accountId") Long accountId);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.tilman.transactions.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
|
|
||||||
|
import de.tilman.transactions.domain.Withdrawal;
|
||||||
|
|
||||||
|
public interface WithdrawalRepository extends PagingAndSortingRepository<Withdrawal, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
INSERT INTO User (id, name, username) VALUES (1, 'Adam', 'adam@mail.com'), (2, 'Betty', 'betty@mail.com');
|
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 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, '2014-06-12');
|
||||||
|
INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (2, 1, 10.00, 1, '2014-06-14');
|
||||||
|
|
||||||
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 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 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
|
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES
|
||||||
(NULL, 1280.81, 1, 1, '2014-06-01', 'Gehalt', null),
|
(NULL, 1280.81, 1, 1, '2014-06-01', 'Gehalt', null),
|
||||||
(NULL, -2.21, 1, 2, '2014-06-10', 'Brot', null),
|
(NULL, -2.21, 1, 2, '2014-06-10', 'Brot', null),
|
||||||
|
|||||||
@@ -28,4 +28,17 @@ body {
|
|||||||
|
|
||||||
.clickable {
|
.clickable {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#accountSelector {
|
||||||
|
text-align: right;
|
||||||
|
margin-right: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-red {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-green {
|
||||||
|
color: green;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
}
|
}
|
||||||
radioButtons[0].checked = true;
|
radioButtons[0].checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.initList = function() {
|
$scope.initList = function() {
|
||||||
@@ -104,6 +103,30 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
amount = '-' + amount;
|
amount = '-' + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle withdrawals
|
||||||
|
if ($scope.transaction.category._links.self.href === 'withdrawal') {
|
||||||
|
if (amount.charAt(0) === '-') {
|
||||||
|
amount = amount.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var Withdrawal = $resource('/withdrawals');
|
||||||
|
|
||||||
|
var newWithdrawal = new Withdrawal({
|
||||||
|
"account" : $scope.account._links.self.href,
|
||||||
|
"amount" : amount,
|
||||||
|
"date" : $scope.transaction.date,
|
||||||
|
"user" : $scope.userinfo._links.self.href
|
||||||
|
});
|
||||||
|
|
||||||
|
newWithdrawal.$save(function(withdrawal) {
|
||||||
|
$scope.refreshList();
|
||||||
|
$scope.lastSubmission = newWithdrawal;
|
||||||
|
console.log(newWithdrawal);
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// via Resource (might be moved into a service)
|
// via Resource (might be moved into a service)
|
||||||
var Transaction = $resource('/transactions');
|
var Transaction = $resource('/transactions');
|
||||||
|
|
||||||
@@ -118,6 +141,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
|
|
||||||
newTransaction.$save(function(transaction) {
|
newTransaction.$save(function(transaction) {
|
||||||
$scope.refreshList();
|
$scope.refreshList();
|
||||||
|
$scope.lastSubmission = newTransaction;
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.deleteLastSubmission = function() {
|
||||||
|
console.log($scope.lastSubmission._links.self.href);
|
||||||
|
var testTrns = $resource($scope.lastSubmission._links.self.href).delete(function() {
|
||||||
|
$scope.lastSubmission = undefined;
|
||||||
|
$scope.refreshList();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<div><select ng-model='account' ng-change='refreshList()' ng-options="account.name for account in accounts track by account.id"></select></div>
|
<div id="accountSelector"><select ng-model='account' ng-change='refreshList()' ng-options="account.name for account in accounts track by account.id"></select></div>
|
||||||
|
|
||||||
|
<div ng-show="lastSubmission" class='ui-state-highlight' style='text-align: center; padding: 0.5ex; width: 30em; margin:auto; margin-bottom: 2em;'>
|
||||||
|
{{lastSubmission.date | date:'dd.MM.yyyy'}}
|
||||||
|
<span ng-class="{ 'color-green': lastSubmission.amount > 0, 'color-red': lastSubmission.amount < 0 }">{{lastSubmission.amount}} €</span>
|
||||||
|
|
||||||
|
<span style='color: red; font-weight: bold;'><a href='' ng-click='deleteLastSubmission()'>löschen</a></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<form name="form" ng-submit="postTransaction()">
|
<form name="form" ng-submit="postTransaction()">
|
||||||
<table border='0' cellpadding='1' style='margin: auto;'>
|
<table border='0' cellpadding='1' style='margin: auto;'>
|
||||||
<tr>
|
<tr>
|
||||||
<td align='right'>Betrag:</td>
|
<td align='right'>Betrag:</td>
|
||||||
<td><input name="amount" ng-model='transaction.amount' type='text' required
|
<td><input name="amount" ng-model='transaction.amount' type='text' required autofocus="autofocus"
|
||||||
ng-pattern="/^[+-]?(?:\d+(?:[\.,]\d{0,2})?|[\.,]\d{1,2})$/" /><span ng-show="form.amount.$error.pattern"><br/>The value
|
ng-pattern="/^[+-]?(?:\d+(?:[\.,]\d{0,2})?|[\.,]\d{1,2})$/" /><span ng-show="form.amount.$error.pattern"><br/>The value
|
||||||
is not valid!</span></td>
|
is not valid!</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user