alles über Spring Data REST Repositories: Vorbereitung

This commit is contained in:
2016-05-01 17:51:29 +02:00
parent 6404a1ee4f
commit e63b5a16d7
5 changed files with 89 additions and 20 deletions
+7 -2
View File
@@ -11,12 +11,17 @@ curl --user adam@mail.com:test -i -X DELETE http://localhost:8080/transactions/4
https://letsencrypt.org/getting-started/ https://letsencrypt.org/getting-started/
http://localhost:8080/transactions?size=10&sort=date,desc
# TODO # TODO
- Auslagen und Entnahmen aufsummieren und anzeigen - alles über findAll filtern http://stackoverflow.com/questions/33018127/spring-data-rest-sort-by-multiple-properties
- account direkt in Transaction anzeigen http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.excerpting-commonly-accessed-data
--> mit neuer Projektion: keine zusätzlichen GET-Requests für Creditor und Category, account per Parameter filtern (wie getDescriptionsByAccount), findFirst10 kann entfernt werden
- Transaktionen in Popup editieren/löschen als Admin
- Liste von Transaktionen anzeigen - Liste von Transaktionen anzeigen
- CSV-Export - CSV-Export
- Verschlüsselung aktivieren - Verschlüsselung aktivieren
- Autocomplete für Notizfeld
- Auslagen zurücksetzen
- Absicherung: DELETE darf von Usern nur auf die letzte Transaktion angewendet werden - Absicherung: DELETE darf von Usern nur auf die letzte Transaktion angewendet werden
@@ -0,0 +1,30 @@
package de.tilman.transactions.repository;
import java.math.BigDecimal;
import java.util.Date;
import org.springframework.data.rest.core.config.Projection;
import de.tilman.transactions.domain.Category;
import de.tilman.transactions.domain.Transaction;
import de.tilman.transactions.domain.User;
/**
* @see http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.excerpting-commonly-accessed-data
*/
@Projection(name = "transactionInlineProjection", types = { Transaction.class })
public interface TransactionInlineProjection {
public Long getId();
public BigDecimal getAmount();
public Date getDate();
public Date getLastChange();
public String getDescription();
public User getCreditor();
public Category getCategory();
// --> account wird direkt per Parameter gefiltert
// public Account getAccount();
}
@@ -7,10 +7,12 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query; 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.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.data.rest.core.annotation.RestResource;
import de.tilman.transactions.domain.Transaction; import de.tilman.transactions.domain.Transaction;
@RepositoryRestResource(excerptProjection = TransactionInlineProjection.class)
public interface TransactionRepository extends PagingAndSortingRepository<Transaction, Long> { public interface TransactionRepository extends PagingAndSortingRepository<Transaction, Long> {
// @RestResource(exported = false) // @RestResource(exported = false)
+46 -18
View File
@@ -1,31 +1,59 @@
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 (1, 1, 20.00, 2, '2015-06-12');
INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (2, 1, 10.00, 1, '2014-06-14'); INSERT INTO Withdrawal(id, account_id, amount, user_id, date) VALUES (2, 1, 10.00, 1, '2015-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, '2015-06-01', 'Gehalt', null),
(NULL, -2.21, 1, 2, '2014-06-10', 'Brot', null), (NULL, -2.21, 1, 2, '2015-06-10', 'Brot', null),
(NULL, -3.41, 1, 2, '2014-06-12', 'Gemüse', null), (NULL, -3.41, 1, 2, '2015-06-12', 'Gemüse', null),
(NULL, -7.81, 1, 3, '2014-06-19', 'Kantine', null), (NULL, -7.81, 1, 3, '2015-06-19', 'Kantine', null),
(NULL, -4.81, 1, 3, '2014-06-18', 'Currywurst', 1), (NULL, -4.81, 1, 3, '2015-06-18', 'Currywurst', 1),
(NULL, -4.50, 1, 3, '2014-06-19', 'Currywurst', null), (NULL, -4.50, 1, 3, '2015-06-19', 'Currywurst', null),
(NULL, -4.50, 1, 3, '2014-06-20', 'Currywurst', null), (NULL, -4.50, 1, 3, '2015-06-20', 'Currywurst', null),
(NULL, -4.50, 2, 3, '2014-06-20', 'Currywurst', null), (NULL, -4.50, 2, 3, '2015-06-20', 'Currywurst', null),
(NULL, -4.09, 1, 3, '2014-06-18', 'Currywurst-Frühstück', null), (NULL, -4.09, 1, 3, '2015-06-18', 'Currywurst-Frühstück', null),
(NULL, -4.90, 1, 3, '2014-06-18', 'Currywurst (Auslage Betty)', 2), (NULL, -4.90, 1, 3, '2015-06-18', 'Currywurst (Auslage Betty)', 2),
(NULL, -8.90, 1, 3, '2014-06-18', 'Curry beim Inder (Auslage Adam)', 1), (NULL, -8.90, 1, 3, '2015-06-18', 'Curry beim Inder (Auslage Adam)', 1),
(NULL, -12.00, 2, 3, '2014-06-18', 'Curry Thai', null), (NULL, -12.00, 2, 3, '2015-06-18', 'Curry Thai', null),
(NULL, 1340.22, 2, 4, '2014-06-02', 'Gehalt Adam', null), (NULL, 1340.22, 2, 4, '2015-06-02', 'Gehalt Adam', null),
(NULL, -12.90, 2, 5, '2014-06-16', 'Host Europe', null); (NULL, -12.90, 2, 5, '2015-06-16', 'Host Europe', null);
-- add as many transactions as needed -- add as many transactions as needed
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, CURRENT_TIMESTAMP(), 'Transaction', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction01', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, CURRENT_TIMESTAMP(), 'Transaction', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction02', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction03', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction04', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction05', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction06', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction07', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction08', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction09', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction10', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction11', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction12', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction13', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction14', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction15', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction16', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction17', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction18', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction19', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction20', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction21', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction22', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction23', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction24', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction25', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction26', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction27', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction28', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, '2015-06-10', 'Transaction29', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2015-06-10', 'Transaction30', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.50, 1, 4, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.50, 1, 4, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit;
@@ -23,6 +23,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
// get recent transactions // get recent transactions
var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get(); var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get();
//var transactions = $resource('/transactions?size=10&sort=date,desc')
transactions.$promise.then(function(data) { transactions.$promise.then(function(data) {
$scope.transactions = transactions._embedded.transactions; $scope.transactions = transactions._embedded.transactions;
@@ -111,6 +112,9 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.initList = function() { $scope.initList = function() {
console.log('initList()'); console.log('initList()');
$scope.transactionsPage = 0;
var userinfo = $resource('/user').get(); var userinfo = $resource('/user').get();
userinfo.$promise.then(function(data) { userinfo.$promise.then(function(data) {
$scope.userid = userinfo.name; $scope.userid = userinfo.name;