problems saving - try curl first

This commit is contained in:
2016-03-08 17:21:39 +01:00
parent 56799eaefe
commit 4113246222
5 changed files with 83 additions and 15 deletions
@@ -19,6 +19,8 @@ public class Transaction {
private Date date;
private Date lastChange;
private String description;
@ManyToOne
@@ -50,6 +52,14 @@ public class Transaction {
this.date = date;
}
public Date getLastChange() {
return lastChange;
}
public void setLastChange(Date lastChange) {
this.lastChange = lastChange;
}
public String getDescription() {
return description;
}
@@ -0,0 +1,27 @@
package de.tilman.transactions.repository;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.stereotype.Component;
import de.tilman.transactions.domain.Transaction;
// see https://spring.io/blog/2015/10/28/react-js-and-spring-data-rest-part-5-security
@Component
@RepositoryEventHandler(Transaction.class)
public class SpringDataRestEventHandler {
private static final Logger log = LoggerFactory.getLogger(SpringDataRestEventHandler.class);
@HandleBeforeCreate
@HandleBeforeSave
public void applyUserInformationUsingSecurityContext(Transaction transaction) {
log.info("Setting date on new transaction: " + transaction.getDescription());
transaction.setLastChange(new Date());
}
}
@@ -13,8 +13,8 @@ import de.tilman.transactions.domain.Transaction;
public interface TransactionRepository extends PagingAndSortingRepository<Transaction, Long> {
@RestResource(exported = false)
Page<Transaction> findAll(Pageable pageable);
// @RestResource(exported = false)
// Page<Transaction> findAll(Pageable pageable);
@RestResource(path = "last10")
List<Transaction> findFirst10ByAccountIdOrderByDateDesc(@Param("accountId") Long accountId);
+29 -7
View File
@@ -2,21 +2,37 @@ var transactionControllers = angular.module('transactionControllers', ['ngResour
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', function($scope, $location, $resource) {
// TODO pass accountId
$scope.accountId = 1;
$scope.initList = function() {
$scope.refreshList = function() {
console.log('refreshList()');
var transactions = $resource('/transactions/search/last10', { accountId: $scope.accountId }).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.transactions[i].account = $resource($scope.transactions[i]._links.account.href).get();
}
// XXX get selected account from frontend
$scope.account = $scope.transactions[0]._links.account;
});
}
$scope.initList = function() {
// TODO pass accountId
$scope.accountId = 1;
console.log('initList()');
$scope.date = new Date();
$scope.refreshList();
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accountId }).get();
@@ -24,14 +40,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.categories = categories._embedded.categories;
// select the first entry as default
$scope.categorySelection = categories._embedded.categories[0];
$scope.category = categories._embedded.categories[0];
});
}
$scope.postTransaction = function() {
// // simple HTTP POST
console.log('postTransaction()');
// simple HTTP POST
// $http.post('/transactions', { "amount" : $scope.amount /* date, */ }).success(function() {
// console.log('REFRESH');
// $scope.initList();
@@ -49,7 +67,11 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
"creditor" : $scope.creditor
});
console.log(newTransaction);
newTransaction.$save();
$scope.refreshList();
};
$scope.showTransaction = function(transaction) {
@@ -3,23 +3,24 @@
<div>
<form role="form" ng-submit="postTransaction()">
<div>
<input ng-model='amount' type='text' size='10' maxlength='10' />
Betrag: <input ng-model='amount' type='number' />
</div>
<div>
<select ng-model='categorySelection' size='1' ng-options="category.name for category in categories track by category._links.self.href">
Kategorie: <select ng-model='category' size='1'
ng-options="category.name for category in categories track by category._links.self.href">
</select>
</div>
<div>
<input ng-model='date' type='text' size='10' maxlength='10' />
Datum: <input ng-model='date' type='date' placeholder="yyyy-MM-dd" required />
</div>
<div>
<input ng-model='description' type='text' size='10' maxlength='10' />
Notiz: <input ng-model='description' type='text' size='10' />
</div>
<div>
<input type="submit"/>
<input type="submit" />
</div>
</form>
<table class="listing">
<tr>
<th>Datum</th>
@@ -35,6 +36,14 @@
</tr>
</table>
<div>
<pre style="font-size: 75%">{{account | json}}</pre>
</div>
<div>
<pre style="font-size: 75%">{{transactions | json}}</pre>
</div>
</div>
</div>
</div>