-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Description
π― 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 readyLine 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
BalanceCheckServiceto 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