Skip to content

πŸ”§ Fix TODOs in Groups Service - Implement Balance ChecksΒ #17

@Devasy

Description

@Devasy

🎯 Overview

There are several TODOs in the Groups Service that need to be addressed to enable proper integration with the Expense Service.

🚨 Current Issues

Balance Check Integration Missing

Currently, these operations in backend/app/groups/service.py have TODO comments for balance checks:

Line 196 in leave_group method:

# TODO: Check for outstanding balances with expense service
# For now, we'll allow leaving without balance check
# This should be implemented when expense service is ready

Line 288 in remove_member method:

# TODO: Check for outstanding balances with expense service
# For now, we'll allow removal without balance check

πŸ“‹ Requirements

1. Implement Balance Check Service

  • Create BalanceCheckService to interact with Expense Service
  • Add method to check if user has outstanding balances in a group
  • Return detailed balance information (amount owed/owed to)

2. Update leave_group Method

  • Call balance check before allowing user to leave
  • Return appropriate error with balance details if user has outstanding debts
  • Allow leaving only when balance is zero

3. Update remove_member Method

  • Check member's balance before removal
  • Prevent removal if member has outstanding balances
  • Provide clear error message with balance information

4. Error Handling Enhancement

  • Create specific exception types for balance-related errors
  • Provide user-friendly error messages
  • Include balance amounts in error responses

πŸ”— Dependencies

  • Requires Expense Service to be implemented first
  • Depends on settlement calculation algorithms
  • Needs balance aggregation endpoints

πŸ—οΈ Implementation Details

Expected API Integration:

# Example of how balance check should work
balance_info = await expense_service.get_user_balance_in_group(user_id, group_id)
if balance_info["net_balance"] != 0:
    raise HTTPException(
        status_code=400, 
        detail=f"Cannot leave group. Outstanding balance: {balance_info['formatted_balance']}"
    )

Error Response Format:

{
  "detail": "Cannot leave group. You have outstanding balances.",
  "balance_info": {
    "net_balance": -25.50,
    "currency": "USD",
    "owed_to": [
      {"user_id": "user123", "amount": 25.50, "user_name": "John Doe"}
    ],
    "owed_from": []
  }
}

🎯 Priority

Medium Priority - Should be implemented after Expense Service is ready.

🏷️ Labels

todo, backend, groups, integration

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions