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 date;
private Date lastChange;
private String description; private String description;
@ManyToOne @ManyToOne
@@ -50,6 +52,14 @@ public class Transaction {
this.date = date; this.date = date;
} }
public Date getLastChange() {
return lastChange;
}
public void setLastChange(Date lastChange) {
this.lastChange = lastChange;
}
public String getDescription() { public String getDescription() {
return description; 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> { public interface TransactionRepository extends PagingAndSortingRepository<Transaction, Long> {
@RestResource(exported = false) // @RestResource(exported = false)
Page<Transaction> findAll(Pageable pageable); // Page<Transaction> findAll(Pageable pageable);
@RestResource(path = "last10") @RestResource(path = "last10")
List<Transaction> findFirst10ByAccountIdOrderByDateDesc(@Param("accountId") Long accountId); List<Transaction> findFirst10ByAccountIdOrderByDateDesc(@Param("accountId") Long accountId);
+27 -5
View File
@@ -2,10 +2,10 @@ var transactionControllers = angular.module('transactionControllers', ['ngResour
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', function($scope, $location, $resource) { transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', function($scope, $location, $resource) {
// TODO pass accountId $scope.refreshList = function() {
$scope.accountId = 1;
console.log('refreshList()');
$scope.initList = function() {
var transactions = $resource('/transactions/search/last10', { accountId: $scope.accountId }).get(); var transactions = $resource('/transactions/search/last10', { accountId: $scope.accountId }).get();
transactions.$promise.then(function(data) { transactions.$promise.then(function(data) {
@@ -14,9 +14,25 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
for (var i = 0; i < $scope.transactions.length; i++) { for (var i = 0; i < $scope.transactions.length; i++) {
$scope.transactions[i].category = $resource($scope.transactions[i]._links.category.href).get(); $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].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(); var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accountId }).get();
@@ -24,14 +40,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.categories = categories._embedded.categories; $scope.categories = categories._embedded.categories;
// select the first entry as default // select the first entry as default
$scope.categorySelection = categories._embedded.categories[0]; $scope.category = categories._embedded.categories[0];
}); });
} }
$scope.postTransaction = function() { $scope.postTransaction = function() {
// // simple HTTP POST console.log('postTransaction()');
// simple HTTP POST
// $http.post('/transactions', { "amount" : $scope.amount /* date, */ }).success(function() { // $http.post('/transactions', { "amount" : $scope.amount /* date, */ }).success(function() {
// console.log('REFRESH'); // console.log('REFRESH');
// $scope.initList(); // $scope.initList();
@@ -49,7 +67,11 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
"creditor" : $scope.creditor "creditor" : $scope.creditor
}); });
console.log(newTransaction);
newTransaction.$save(); newTransaction.$save();
$scope.refreshList();
}; };
$scope.showTransaction = function(transaction) { $scope.showTransaction = function(transaction) {
@@ -3,20 +3,21 @@
<div> <div>
<form role="form" ng-submit="postTransaction()"> <form role="form" ng-submit="postTransaction()">
<div> <div>
<input ng-model='amount' type='text' size='10' maxlength='10' /> Betrag: <input ng-model='amount' type='number' />
</div> </div>
<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> </select>
</div> </div>
<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>
<div> <div>
<input ng-model='description' type='text' size='10' maxlength='10' /> Notiz: <input ng-model='description' type='text' size='10' />
</div> </div>
<div> <div>
<input type="submit"/> <input type="submit" />
</div> </div>
</form> </form>
@@ -35,6 +36,14 @@
</tr> </tr>
</table> </table>
<div>
<pre style="font-size: 75%">{{account | json}}</pre>
</div>
<div>
<pre style="font-size: 75%">{{transactions | json}}</pre>
</div>
</div> </div>
</div> </div>
</div> </div>