Skip to main content

Overview

GroupRepository handles all group-related data operations including creating groups, fetching group lists, updating group details, and deleting groups. Interface: backend/GroupRepository.kt:12
Implementation: backend/SupabaseGroupRepository.kt:45

Interface Definition

Implementation

SupabaseGroupRepository

The repository maintains an internal state flow that’s initialized to Loading and automatically refreshes on creation.

Methods

listGroups

Returns a reactive Flow of all groups for the current user.
Returns: Flow<DataResult<List<Group>>> - Stream of group list with loading/error states Example Usage:
Implementation:

getGroup

Returns a Flow for a single group by ID.
String
required
The unique identifier of the group to retrieve
Returns: Flow<Group> - Stream of the requested group (returns placeholder if not found) Example Usage:
Implementation:

createGroup

Creates a new group with the current user as owner.
String
required
The display name for the new group
GroupIcon
required
The icon to display for the group (e.g., GroupIcon.Home, GroupIcon.Flight)
Returns: Group - The newly created group object Throws: Exception if Supabase call fails Example Usage:
Supabase Implementation:
RPC Function: create_group_with_owner - Creates the group and adds the current user as a member

updateGroup

Updates an existing group’s name and icon.
String
required
The ID of the group to update
String
required
The new name for the group
GroupIcon
required
The new icon for the group
Example Usage:
Supabase Implementation:

deleteGroup

Deletes a group and all associated data (expenses, splits, members).
String
required
The ID of the group to delete
Warning: This operation is irreversible and cascades to all related data. Example Usage:
Supabase Implementation:
RPC Function: delete_group_cascade - Deletes the group and all related records

refreshGroups

Forces a refresh of the groups list from Supabase.
Example Usage:
Supabase Implementation:
RPC Function: get_my_groups_summary - Returns groups with member counts and balance calculations

Data Models

Group

Source: models/Group.kt:7

Internal Models

Error Handling

Error States

The repository wraps all Supabase operations in try-catch blocks and updates the state flow:

Common Errors

  • Network errors: Connection timeout, no internet
  • Authentication errors: Invalid session, expired token
  • Database errors: Constraint violations, RLS policy failures

See Also