4.6 KiB
4.6 KiB
Plan: Groups & Batches Feature
API Surface (from Postman)
Groups
GET /api/public/recipient-groups?userId={userId}— list groupsGET /api/public/recipient-groups/members?recipientGroupId={id}— list membersPOST /api/public/recipient-groups— create group- Body:
{ name, description, userId, recipients: [{name, phoneNumber, latestProviderLabel, account}] }
- Body:
Batches
GET /api/public/group-batches?recipientGroupId={id}&sort=createdAt,desc— list batchesGET /api/public/group-batches/items?groupBatchId={id}&sort=createdAt,desc— list batch itemsPOST /api/public/group-batches— create batch (recipientGroupId, userId, currency, amount, paymentProcessorLabel, paymentProcessorName, paymentProcessorImage, transactionTemplate)POST /api/public/group-batches/{batchId}/confirm— confirm batchPOST /api/public/group-batches/{batchId}/request— request batch (payment)POST /api/public/group-batches/{batchId}/poll— poll batch status
Files To Create
Phase 1: Models
lib/models/recipient_group_model.dart— RecipientGroup, RecipientMember, CreateGroupRequestlib/models/group_batch_model.dart— GroupBatch, GroupBatchItem, CreateBatchRequest (transactionTemplate typed as TransactionModel from lib/screens/transactions/transaction_model.dart), BatchActionRequest. No separate TransactionTemplate class needed.
Phase 2: Controllers
lib/screens/groups/group_controller.dart— ChangeNotifier, list/create groups, list memberslib/screens/groups/batch_controller.dart— ChangeNotifier, list/create batches, list items, confirm/request/poll
Phase 3: Screens
lib/screens/groups/groups_screen.dart— list all groupslib/screens/groups/group_create_screen.dart— create group form (name, description, multiline textarea: one recipient per line asname,account; phoneNumber defaults to account value)lib/screens/groups/group_detail_screen.dart— tabbed view: Batches first (default), Members second; receives RecipientGroup via extra; FAB on Batches tab to create new batchlib/screens/groups/batch_create_screen.dart— create batch form (provider, processor, amount, currency); on success navigate to BatchDetailScreen passing created batch via extralib/screens/groups/batch_detail_screen.dart— batch items list + Confirm/Request/Poll action buttonslib/screens/groups/batch_item_screen.dart— single batch item detail view
Phase 4: Integration
lib/navbar.dart— add Groups as 3rd nav item (index 2)lib/main.dart— add routes + GroupController + BatchController providers
Routes
/groups→ GroupsScreen/groups/create→ GroupCreateScreen/groups/:groupId→ GroupDetailScreen/groups/:groupId/batches/create→ BatchCreateScreen/groups/:groupId/batches/:batchId→ BatchDetailScreen/groups/:groupId/batches/:batchId/items/:itemId→ BatchItemScreen
Action Return Types
createBatch→ApiResponse<GroupBatch>confirmBatch→ApiResponse<GroupBatch>requestBatch→ApiResponse<TransactionModel>(reuses TransactionModel)pollBatch→ApiResponse<GroupBatch>- List endpoints →
ApiResponse<PageableModel<T>>
BatchDetailScreen Auto-Poll Logic
After Request action:
requestBatch()returnsTransactionModel- Check
transaction.pollingStatus— if successful (e.g.SUCCESS,COMPLETE) → no poll needed, refresh batch - Otherwise → auto-trigger
pollBatch()immediately without user input - If auto-poll fails (network error / non-terminal status) → show Poll button for manual retry
- Batch status from poll response drives UI state (show/hide action buttons)
Key Patterns
- Controllers extend ChangeNotifier
- Models use
@JsonSerializablewith generated.g.dartfiles - All network calls use
ApiResponse<T>wrapping pattern (try/catch in controller) - Use
ListenableBuilderin screens - Read
userId/tokenfrom SharedPreferences - Pass extra data via GoRouter
extra:parameter idempotencyKeyfor batch actions generated as"batch-{batchId}-{action}-{timestamp}"- Navbar: add Groups at index 2, update
_handleTap+_calculateSelectedIndex
Member Input Parsing (group_create_screen)
- One recipient per line:
name,account phoneNumberdefaults toaccountvaluelatestProviderLabeldefaults to""
Decisions
TransactionModelreused as-is fortransactionTemplatefield — no wrapper class- No pagination on groups/batches lists in this iteration
- No edit/delete for groups or batches in scope
- Poll button only shown as manual fallback after auto-poll failure