Skip to main content

Overview

ExpensesRepository handles all expense-related operations including creating expenses with splits, updating existing expenses, and tracking expenses across groups. Interface: backend/ExpensesRepository.kt:15
Implementation: backend/SupabaseExpensesRepository.kt:21

Interface Definition

Implementation

SupabaseExpensesRepository

The repository caches expenses by group ID for efficient reactive updates.

Basic Expense Methods

listExpenses

Fetches all expenses from the database.
Returns: List<Expense> - All expenses in the system Supabase Query:

listExpensesByGroup

Fetches all expenses for a specific group.
String
required
The ID of the group to fetch expenses for
Returns: List<Expense> - All expenses in the specified group Example Usage:
Supabase Query:

listGroupExpenses

Fetches expenses with their splits for a specific group.
String
required
The ID of the group to fetch expenses for
Returns: List<GroupExpense> - Expenses with split information Supabase Query:
Database View: Uses group_expenses_with_splits view that joins expenses with their splits

getExpenseById

Fetches a single expense by ID.
String
required
The unique identifier of the expense
Returns: Expense? - The expense or null if not found Supabase Query:

getGroupExpenseById

Fetches a single expense with its splits.
String
required
The unique identifier of the expense
Returns: GroupExpense? - The expense with splits or null if not found Supabase Implementation:

Creating Expenses

createExpense

Creates a basic expense without custom splits.
String
required
The group this expense belongs to
String
required
The merchant or description of the expense
Long
required
The total amount in cents (e.g., 1000 = $10.00)
String
required
How to split the expense: “EQUAL”, “PERCENTAGE”, or “EXACT”
Returns: Expense - The created expense Example Usage:
Supabase Implementation:

createExpenseWithSplits

Creates an expense with custom split amounts for each member.
String
required
The group this expense belongs to
String
required
The merchant or description of the expense
Long
required
The total amount in cents
String
required
Currency code (e.g., “USD”, “EUR”)
String
required
Split method: “EQUAL”, “PERCENTAGE”, “EXACT”
List<ExpenseSplit>
required
List of split allocations for each member
Returns: GroupExpense - The created expense with splits Example Usage:
Supabase Implementation:
RPC Function: create_expense_with_splits - Atomically creates expense and splits

Updating Expenses

updateExpense

Updates an expense’s basic properties.
String
required
The ID of the expense to update
String
required
The group ID (can be changed to move expense)
String
required
Updated description/merchant
Long
required
Updated amount in cents
String
required
Updated split method
String
required
Updated currency code
Returns: Expense - The updated expense Supabase Implementation:

updateExpenseSplits

Updates the split allocations for an expense.
String
required
The ID of the expense to update splits for
List<ExpenseSplit>
required
New split allocations
Example Usage:
Supabase Implementation:
RPC Function: update_expense_splits - Replaces all splits for an expense

deleteExpense

Deletes an expense and all its splits.
String
required
The ID of the expense to delete
Supabase Implementation:

Reactive Observations

observeGroupExpenses

Returns a Flow of expenses for a specific group.
String
required
The group ID to observe expenses for
Returns: Flow<List<GroupExpense>> - Stream of expense updates Example Usage:
Implementation:

observeAllGroupExpenses

Returns a Flow of all expenses across all groups.
Returns: Flow<List<GroupExpense>> - Stream of all expenses Implementation:

refreshGroupExpenses

Forces a refresh of expenses for a specific group.
String
required
The group ID to refresh expenses for
Implementation:

refreshAllExpenses

Forces a refresh of all expenses.
Implementation:

Data Models

Expense

Source: models/Expense.kt:7

ExpenseSplit

Source: models/GroupExpense.kt:8
Fields:
  • userId: The member this split belongs to
  • amountCents: This member’s share of the expense
  • isCoveredBy: Optional user ID if someone is covering this member’s share

GroupExpense

Source: models/GroupExpense.kt:15

Split Calculation Utilities

Source: models/GroupExpense.kt:30

splitEqually

Divides an amount evenly across users:
Example:

splitByPercentage

Divides an amount by percentage shares:
Example:

Error Handling

All suspend functions may throw exceptions:

See Also