Phase 1: Add expense statistics endpoint (GET /expenses/statistics)#191
Open
mnindrazaka wants to merge 2 commits into
Open
Phase 1: Add expense statistics endpoint (GET /expenses/statistics)#191mnindrazaka wants to merge 2 commits into
mnindrazaka wants to merge 2 commits into
Conversation
…189) Claude-Session: https://claude.ai/code/session_01AvitwGYxvAfyBcboGWncQZ Co-authored-by: Claude <noreply@anthropic.com>
Mirrors the existing /transactions/statistics pattern: groups non-deleted
expenses by period (date|month, default month) and budget, joined to
budgets so soft-deleted budgets still appear under their original name.
Adds the OpenAPI schema/path needed to generate the response types, plus
usecase/repo/handler/route wiring and unit + MySQL integration tests
covering grouping, per-budget split sums, inclusive date bounds, deleted
expense exclusion, soft-deleted budget history, and the
/expenses/statistics vs /expenses/{expenseId} route ordering.
Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the backend for expense statistics, adding a new
GET /expenses/statisticsendpoint that mirrors the existing transaction statistics pattern. This is Phase 1 of the Expense Statistics feature (seedocs/prd-expense-statistics.md), focusing purely on the backend API layer.Key Changes
Backend API Layer
ExpenseStatisticdomain entity withdate,budgetId,budgetName, andtotalfieldsGetExpenseStatistics()repository method in MySQL that:endDate(half-open SQL implementation)GetExpenseStatistics()usecase with validation: rejects requests wherestartDate > endDateGetExpenseStatistics()handler that parses query parameters (groupBy,startDate,endDate) and returns 400 on malformed dates/expenses/statisticsroute before/expenses/{expenseId}to prevent route capture collisionOpenAPI Contract
/expenses/statisticsendpoint definition with query parameters and response schemaExpenseStatisticandExpenseStatisticResponseschemas (Kubb will regenerate TS client)Testing
/expenses/statisticsis not captured by the{expenseId}wildcardImplementation Details
{date, budgetId, budgetName, total}matching the SQL query directly; client-side pivot/zero-fill/aggregation is deferred to later phases%d-%m-%Yfor day grouping,%m-%Yfor month grouping (consistent with transaction statistics)endDateis implemented as half-open SQL (< endDate + 1 day) to include the entire daydeleted_at IS NOT NULLare excluded; budgets withdeleted_at IS NOT NULLare included (preserving historical labels)expenses.totalandidx_expenses_budget_idThis PR is independently shippable and verifiable with
curlagainst seeded data. Subsequent phases will add frontend UI, dashboard restructuring, and mobile support.https://claude.ai/code/session_014uLjCgvSSBgMyKeBAqDDCK