exposed IDs and account switching
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package de.tilman.transactions;
|
||||||
|
|
||||||
|
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||||
|
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import de.tilman.transactions.domain.Account;
|
||||||
|
import de.tilman.transactions.domain.Category;
|
||||||
|
import de.tilman.transactions.domain.Transaction;
|
||||||
|
import de.tilman.transactions.domain.User;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {
|
||||||
|
|
||||||
|
// TODO Ask someone who knows better how to do all of this without exposing the IDs. Parsing URLs can't be the answer.
|
||||||
|
@Override
|
||||||
|
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
||||||
|
|
||||||
|
config.exposeIdsFor(Account.class, Category.class, Transaction.class, User.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package de.tilman.transactions.controller;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public Principal user(Principal user) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,11 +19,12 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
|
|
||||||
if (typeof $scope.categories !== 'undefined') {
|
if (typeof $scope.categories !== 'undefined') {
|
||||||
// TODO default-Kategorie sollte per Account einstellbar sein
|
// TODO default-Kategorie sollte per Account einstellbar sein
|
||||||
|
console.log('DID IT!');
|
||||||
$scope.transaction.category = $scope.categories[0];
|
$scope.transaction.category = $scope.categories[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// get recent transactions
|
// get recent transactions
|
||||||
var transactions = $resource('/transactions/search/last10', { accountId: $scope.accountId }).get();
|
var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get();
|
||||||
|
|
||||||
transactions.$promise.then(function(data) {
|
transactions.$promise.then(function(data) {
|
||||||
$scope.transactions = transactions._embedded.transactions;
|
$scope.transactions = transactions._embedded.transactions;
|
||||||
@@ -37,34 +38,31 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.initList = function() {
|
$scope.initList = function() {
|
||||||
|
|
||||||
// TODO get account from frontend
|
|
||||||
$scope.accountId = 1;
|
|
||||||
$scope.account = 'http://localhost:8080/accounts/1';
|
|
||||||
|
|
||||||
//http://localhost:8080/accounts/search/findByUserName?username=betty@mail.com
|
|
||||||
|
|
||||||
// var accounts = $resource('/accounts/search/findByUserName', { username: $scope.accountId }).get();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log('initList()');
|
console.log('initList()');
|
||||||
|
var userinfo = $resource('/user').get();
|
||||||
|
userinfo.$promise.then(function(data) {
|
||||||
|
$scope.username = userinfo.name;
|
||||||
|
|
||||||
$scope.refreshList();
|
var accountInfo = $resource('/accounts/search/findByUserName', { username: userinfo.name }).get();
|
||||||
|
accountInfo.$promise.then(function(data) {
|
||||||
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accountId }).get();
|
$scope.accounts = accountInfo._embedded.accounts;
|
||||||
|
$scope.account = $scope.accounts[0];
|
||||||
|
|
||||||
|
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accounts[0].id }).get();
|
||||||
categories.$promise.then(function(data) {
|
categories.$promise.then(function(data) {
|
||||||
$scope.categories = categories._embedded.categories;
|
$scope.categories = categories._embedded.categories;
|
||||||
|
$scope.refreshList();
|
||||||
// select the first entry as default
|
});
|
||||||
$scope.transaction.category = categories._embedded.categories[0];
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.refreshAccount = function() {
|
||||||
|
console.log('BINGO!');
|
||||||
|
$scope.refreshList();
|
||||||
|
};
|
||||||
|
|
||||||
$scope.postTransaction = function() {
|
$scope.postTransaction = function() {
|
||||||
|
|
||||||
// via Resource (might be moved into a service)
|
// via Resource (might be moved into a service)
|
||||||
@@ -88,6 +86,10 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
$location.path('/transaction/' + transaction._links.self.href);
|
$location.path('/transaction/' + transaction._links.self.href);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// initialize (http://stackoverflow.com/a/25662066/3761783)
|
||||||
|
$scope.initList();
|
||||||
|
|
||||||
} ]);
|
} ]);
|
||||||
|
|
||||||
transactionControllers.controller('TransactionDetailCtrl', [ '$scope', '$routeParams', '$resource', '$location', function($scope, $routeParams, $resource, $location) {
|
transactionControllers.controller('TransactionDetailCtrl', [ '$scope', '$routeParams', '$resource', '$location', function($scope, $routeParams, $resource, $location) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div ng-init="initList()">
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<div><select ng-model='user.accounts' ng-options="account.name for account in accounts"></select></div>
|
<div><select ng-model='account' ng-change='refreshAccount()' ng-options="account.name for account in accounts track by account.id"></select></div>
|
||||||
<div>
|
<div>
|
||||||
<form role="form" ng-submit="postTransaction()">
|
<form role="form" ng-submit="postTransaction()">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user