From aed32a4a286b3062d1bde0a48251abf8392e96d6 Mon Sep 17 00:00:00 2001 From: Tilman Date: Sat, 9 Nov 2019 13:36:27 +0100 Subject: [PATCH] Expenses on budget per month --- .../transactions/repository/CategoryRepository.java | 11 ++++++++--- src/main/resources/data-h2.sql | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/tilman/transactions/repository/CategoryRepository.java b/src/main/java/de/tilman/transactions/repository/CategoryRepository.java index d7d7a3b..4ee8ebf 100644 --- a/src/main/java/de/tilman/transactions/repository/CategoryRepository.java +++ b/src/main/java/de/tilman/transactions/repository/CategoryRepository.java @@ -19,10 +19,15 @@ public interface CategoryRepository extends PagingAndSortingRepository findByAccountIdOrderByPositionAsc(@Param("accountId") Long accountId); - // http://localhost:8084/api/categories/search/expenseLevel?accountId=1&categoryId=1 - @RestResource(path = "expenseLevel") + // http://localhost:8084/api/categories/search/expenseLevelYear?accountId=1&categoryId=1 + @RestResource(path = "expenseLevelYear") @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); + Double getYearExpenseLevelForCategory(@Param("accountId") Long accountId, @Param("categoryId") Long categoryId); + + // http://localhost:8084/api/categories/search/expenseLevelMonth?accountId=2&categoryId=5 + @RestResource(path = "expenseLevelMonth") + @Query("SELECT sum(t.amount) FROM Transaction t WHERE t.account.id = :accountId AND t.category.id = :categoryId and DATE > (CURRENT_DATE() - DAY_OF_MONTH(CURRENT_DATE()))") + Double getMonthExpenseLevelForCategory(@Param("accountId") Long accountId, @Param("categoryId") Long categoryId); @PreAuthorize("hasRole('ROLE_ADMIN')") @Override diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql index 01bc92c..528f387 100644 --- a/src/main/resources/data-h2.sql +++ b/src/main/resources/data-h2.sql @@ -73,6 +73,6 @@ INSERT INTO Transaction (id, amount, account_id, category_id, date, description, 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; +INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.90, 2, 5, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit; --SCRIPT TO 'h2export.sql'; \ No newline at end of file