From 70d6b42539fc028dde5ea92f6ce762c843bd506f Mon Sep 17 00:00:00 2001 From: Tilman Liero Date: Tue, 8 Mar 2016 22:31:37 +0100 Subject: [PATCH] C of CRUD --- README.md | 4 +++- .../transactions/SecurityConfiguration.java | 6 +++--- src/main/resources/static/js/controllers.js | 20 +++++++++++-------- .../static/partials/transaction-list.html | 8 ++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 192731d..d49c2b7 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -Aloha, funky time! \ No newline at end of file +Aloha, funky time! + +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 \ No newline at end of file diff --git a/src/main/java/de/tilman/transactions/SecurityConfiguration.java b/src/main/java/de/tilman/transactions/SecurityConfiguration.java index 8989491..83a2bef 100644 --- a/src/main/java/de/tilman/transactions/SecurityConfiguration.java +++ b/src/main/java/de/tilman/transactions/SecurityConfiguration.java @@ -23,9 +23,9 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // Basis-Schutz: Nur autorisierte Zugriffe (feingranulare Steuerung über Assertions) - http.authorizeRequests() - .antMatchers(HttpMethod.GET, "/public/**").permitAll() - .anyRequest().authenticated(); +// http.authorizeRequests() +// .antMatchers(HttpMethod.GET, "/public/**").permitAll() +// .anyRequest().authenticated(); // http.httpBasic(); // XXX mit HTTP Basic Auth funktioniert der Logout nicht richtig http.formLogin(); diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 7ab0451..b029bbb 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -14,19 +14,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' 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 + // TODO get account from frontend $scope.accountId = 1; + $scope.account = 'http://localhost:8080/accounts/1'; console.log('initList()'); @@ -63,15 +60,22 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' "amount" : $scope.amount, "date" : $scope.date, "description" : $scope.description, - "category" : $scope.category, + "category" : $scope.category._links.self.href, "creditor" : $scope.creditor }); console.log(newTransaction); - newTransaction.$save(); + // create copy of transaction object + var newTransactionCopy = (JSON.parse(JSON.stringify(newTransaction))); + + $scope.newTransaction = newTransaction; + $scope.newTransactionCopy = newTransactionCopy; + + newTransaction.$save(function(transaction, putResponseHeaders) { + $scope.refreshList(); + }); - $scope.refreshList(); }; $scope.showTransaction = function(transaction) { diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/partials/transaction-list.html index 1892e82..ac8fb4d 100644 --- a/src/main/resources/static/partials/transaction-list.html +++ b/src/main/resources/static/partials/transaction-list.html @@ -37,11 +37,15 @@
-
{{account | json}}
+
{{newTransaction | json}}
-
{{transactions | json}}
+
{{newTransactionCopy | json}}
+
+ +
+
{{account | json}}