diff --git a/README.md b/README.md index 8b79efe..23dc424 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,6 @@ curl -i -X POST -H "Content-Type:application/json" -d '{"account":"http://localh curl --user adam@mail.com:test -i -X DELETE http://localhost:8080/transactions/4 - - -https://letsencrypt.org/getting-started/ - - http://localhost:8080/transactions?size=10&sort=date,desc - 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 @@ -18,6 +14,12 @@ https://letsencrypt.org/getting-started/ +# Test-Datenbank lokal erreichbar machen: +Test-Optionen in Application.java und SecurityConfiguration.java aktivieren +Danach ist die Datenbank unter http://localhost:8084/console/ erreichbar + + + # TODO - Server: logs konfigurieren - Transaktionen mit Passwort-Management ausstatten, Usermanagement korrekt aufsetzen und Rollen durchreichen (derzeit noch inMemoryAuthentication) diff --git a/src/main/java/de/tilman/transactions/domain/Category.java b/src/main/java/de/tilman/transactions/domain/Category.java index 49bd04e..f37e07c 100644 --- a/src/main/java/de/tilman/transactions/domain/Category.java +++ b/src/main/java/de/tilman/transactions/domain/Category.java @@ -1,5 +1,7 @@ package de.tilman.transactions.domain; +import java.math.BigDecimal; + import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -21,7 +23,11 @@ public class Category { private Integer position; private Boolean retired = false; - + + private Boolean incomeCategory = false; + + private BigDecimal budget; + public Account getAccount() { return account; } @@ -58,4 +64,21 @@ public class Category { this.retired = retired; } + public Boolean isIncomeCategory() { + return incomeCategory; + } + + public void setIncomeCategory(Boolean incomeCategory) { + this.incomeCategory = incomeCategory; + } + + public BigDecimal getBudget() { + return budget; + } + + public void setBudget(BigDecimal budget) { + this.budget = budget; + } + + } diff --git a/src/main/java/de/tilman/transactions/repository/CategoryRepository.java b/src/main/java/de/tilman/transactions/repository/CategoryRepository.java index 5702c3c..d7d7a3b 100644 --- a/src/main/java/de/tilman/transactions/repository/CategoryRepository.java +++ b/src/main/java/de/tilman/transactions/repository/CategoryRepository.java @@ -4,6 +4,7 @@ import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RestResource; @@ -18,6 +19,11 @@ public interface CategoryRepository extends PagingAndSortingRepository findByAccountIdOrderByPositionAsc(@Param("accountId") Long accountId); + // http://localhost:8084/api/categories/search/expenseLevel?accountId=1&categoryId=1 + @RestResource(path = "expenseLevel") + @Query("SELECT sum(t.amount) FROM Transaction t WHERE t.account.id = :accountId AND t.category.id = :categoryId and DATE > (CURRENT_DATE() - DAY_OF_YEAR(CURRENT_DATE()))") + Integer getExpenseLevelForCategory(@Param("accountId") Long accountId, @Param("categoryId") Long categoryId); + @PreAuthorize("hasRole('ROLE_ADMIN')") @Override Category save(Category category); diff --git a/src/main/java/de/tilman/transactions/repository/TransactionRepository.java b/src/main/java/de/tilman/transactions/repository/TransactionRepository.java index c94bd9c..261aa40 100644 --- a/src/main/java/de/tilman/transactions/repository/TransactionRepository.java +++ b/src/main/java/de/tilman/transactions/repository/TransactionRepository.java @@ -29,6 +29,7 @@ public interface TransactionRepository extends PagingAndSortingRepository getDescriptionsByAccount(@Param("accountId") Long accountId, @Param("prefix") String prefix, Pageable pageable); + // http://localhost:8084/api/transactions/search/expenses?accountId=1&userId=1 @RestResource(path = "expenses") @Query("SELECT t FROM Transaction t WHERE t.account.id = :accountId AND t.creditor.id = :userId ORDER BY t.date DESC") List getTransactionsForCreditorByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId); diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql index 2d66304..01bc92c 100644 --- a/src/main/resources/data-h2.sql +++ b/src/main/resources/data-h2.sql @@ -1,18 +1,18 @@ INSERT INTO User (id, name, username) VALUES (1, 'Adam', 'adam'), (2, 'Betty', 'betty'), (3, 'Curt', 'curt'); INSERT INTO Account (id, name, owner_id) VALUES (1, 'Gemeinschaftskonto', 1), (2, 'Konto Adam', 1); -INSERT INTO Category (id, name, account_id, position, retired) VALUES - (null, 'Essen - Lebensmittel', 1, 2, false), - (null, 'Einnahmen - Gehalt', 1, 1, false), - (null, 'Essen - Arbeit', 1, 3, false), - (null, 'Sonstiges - Projekt 1000', 1, 4, true), - (null, 'Wohnen - Haushalt', 1, 5, false), - (null, 'Private Entnahme', 1, 6, false), - (null, 'Einnahmen - Gehalt', 2, 1, false), - (null, 'Technik - Server und Hosting', 2, 2, false), - (null, 'Essen - Restaurant & Café', 1, 6, true), - (null, 'Essen - Süßwaren & Genussmittel', 1, 7, true), - (null, 'Familie - Baby', 1, 8, true); +INSERT INTO Category (id, name, account_id, position, retired, budget) VALUES + (null, 'Essen - Lebensmittel', 1, 2, false, 1000.0), + (null, 'Einnahmen - Gehalt', 1, 1, false, 70000.0), + (null, 'Essen - Arbeit', 1, 3, false, 400.0), + (null, 'Sonstiges - Projekt 1000', 1, 4, true, 2000.0), + (null, 'Wohnen - Haushalt', 1, 5, false, 830.0), + (null, 'Private Entnahme', 1, 6, false, 0.0), + (null, 'Einnahmen - Gehalt', 2, 1, false, 50000.0), + (null, 'Technik - Server und Hosting', 2, 2, false, 230.0), + (null, 'Essen - Restaurant & Café', 1, 6, true, 380.0), + (null, 'Essen - Süßwaren & Genussmittel', 1, 7, true, 120.0), + (null, 'Familie - Baby', 1, 8, true, 800.0); INSERT INTO Account_User (account_id, user_id) VALUES (1, 1), (1, 2), (1, 3), (2, 1); @@ -22,56 +22,57 @@ INSERT INTO Matcher (id, account_id, position, type_matcher_code, date_matcher_c (NULL, 1, 3, null, null, 'return /\bNETTO\b/.test(x)', null, 1, 'Netto'); INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES - (NULL, 1280.81, 1, 2, '2016-04-01 14:14:14', 'Gehalt', null), - (NULL, -2.21, 1, 1, '2016-04-10', 'Brot', null), - (NULL, -3.41, 1, 1, '2016-04-12', 'Gemüse', null), - (NULL, -7.81, 1, 3, '2016-04-19', 'Kantine', null), - (NULL, -4.81, 1, 3, '2016-04-18', 'Currywurst (Auslage Adam)', 1), - (NULL, -4.50, 1, 3, '2016-04-19', 'Currywurst', null), - (NULL, -4.50, 1, 3, '2016-04-20', 'Currywurst', null), - (NULL, -4.09, 1, 3, '2016-04-18', 'Currywurst-Frühstück', null), - (NULL, -4.90, 1, 3, '2016-04-18', 'Currywurst (Auslage Betty)', 2), - (NULL, -8.90, 1, 3, '2016-04-18', 'Curry beim Inder (Auslage Adam)', 1), + (NULL, -217.17, 1, 1, '2018-12-12', 'Essen letztes Jahr', null), + (NULL, 1280.81, 1, 2, '2019-10-01 14:14:14', 'Gehalt', null), + (NULL, -2.21, 1, 1, '2019-10-10', 'Brot', null), + (NULL, -3.41, 1, 1, '2019-10-12', 'Gemüse', null), + (NULL, -7.81, 1, 3, '2019-10-19', 'Kantine', null), + (NULL, -4.81, 1, 3, '2019-10-18', 'Currywurst (Auslage Adam)', 1), + (NULL, -4.50, 1, 3, '2019-10-19', 'Currywurst', null), + (NULL, -4.50, 1, 3, '2019-10-20', 'Currywurst', null), + (NULL, -4.09, 1, 3, '2019-10-18', 'Currywurst-Frühstück', null), + (NULL, -4.90, 1, 3, '2019-10-18', 'Currywurst (Auslage Betty)', 2), + (NULL, -8.90, 1, 3, '2019-10-18', 'Curry beim Inder (Auslage Adam)', 1), - (NULL, -20, 1, 4, '2016-04-12 18:20:15', 'Entnahme Betty', 2), - (NULL, -10, 1, 4, '2016-04-14 10:03:00', 'Entnahme Adam', 1), + (NULL, -20, 1, 4, '2019-10-12 18:20:15', 'Entnahme Betty', 2), + (NULL, -10, 1, 4, '2019-10-14 10:03:00', 'Entnahme Adam', 1), - (NULL, 1340.22, 2, 5, '2016-04-02', 'Gehalt Adam', null), - (NULL, -4.50, 2, 6, '2016-04-20', 'WebPack', null), - (NULL, -12.90, 2, 6, '2016-04-16', 'Host Europe', null); + (NULL, 1340.22, 2, 5, '2019-10-02', 'Gehalt Adam', null), + (NULL, -4.50, 2, 6, '2019-10-20', 'WebPack', null), + (NULL, -12.90, 2, 6, '2019-10-16', 'Host Europe', null); -- add as many transactions as needed -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction01', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction02', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction03', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction04', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction05', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction06', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction07', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction08', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction09', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction10', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction11', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction12', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction13', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction14', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction15', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction16', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction17', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction18', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction19', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction20', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction21', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction22', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction23', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction24', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction25', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction26', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction27', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction28', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2016-04-01', 'Transaction29', null); Commit; -INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2016-04-01', 'Transaction30', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction01', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction02', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction03', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction04', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction05', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction06', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction07', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction08', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction09', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction10', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction11', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction12', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction13', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction14', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction15', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction16', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction17', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction18', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction19', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction20', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction21', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction22', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction23', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction24', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction25', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction26', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction27', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction28', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction29', null); Commit; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction30', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.50, 2, 5, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit; --SCRIPT TO 'h2export.sql'; \ No newline at end of file