refactor: update agent and lender filtering logic to categorize profiles by type ID

This commit is contained in:
pradeepkumar
2026-03-30 14:58:09 +05:30
parent d507a52b87
commit b3905865d6

View File

@@ -64,54 +64,56 @@ class TopProfessionalsNotifier extends StateNotifier<TopProfessionalsState> {
final agentTypes = await _repository.getAgentTypes(); final agentTypes = await _repository.getAgentTypes();
state = state.copyWith(agentTypes: agentTypes); state = state.copyWith(agentTypes: agentTypes);
// Find agent and lender type IDs by name // Find lender type ID
String? agentTypeId;
String? lenderTypeId; String? lenderTypeId;
final nonLenderTypeIds = <String>[];
for (final type in agentTypes) { for (final type in agentTypes) {
final name = type.name.toLowerCase(); final name = type.name.toLowerCase();
if (name.contains('lender') || name.contains('lending')) { if (name.contains('lender') || name.contains('lending')) {
lenderTypeId = type.id; lenderTypeId = type.id;
} else if (name.contains('professional') || } else {
name.contains('agent') || nonLenderTypeIds.add(type.id);
name.contains('realtor') ||
name.contains('broker')) {
agentTypeId = type.id;
} }
} }
// If no specific agent type found, use first type as agents // Fetch agents (all non-lender types) and lenders in parallel
if (agentTypeId == null && agentTypes.isNotEmpty) { final agentsFuture = _repository.searchAgents(
agentTypeId = agentTypes.first.id; limit: 10,
// Look for lender in remaining sortBy: 'averageRating',
for (final type in agentTypes) { sortOrder: 'desc',
if (type.id != agentTypeId) { );
lenderTypeId = type.id; final lendersFuture = lenderTypeId != null
break; ? _repository.searchAgents(
} agentTypeId: lenderTypeId,
} limit: 10,
} sortBy: 'averageRating',
sortOrder: 'desc',
)
: null;
// Fetch agents and lenders in parallel final agentsResult = await agentsFuture;
final results = await Future.wait([ final lendersResult = lendersFuture != null ? await lendersFuture : null;
_repository.searchAgents(
agentTypeId: agentTypeId, // Split: agents = non-lender profiles, lenders = lender profiles
limit: 10, final allAgents = agentsResult.data;
sortBy: 'averageRating', List<AgentProfile> agents;
sortOrder: 'desc', List<AgentProfile> lenders;
),
if (lenderTypeId != null) if (lenderTypeId != null) {
_repository.searchAgents( agents = allAgents
agentTypeId: lenderTypeId, .where((a) => a.agentType?.id != lenderTypeId)
limit: 10, .toList();
sortBy: 'averageRating', lenders = lendersResult?.data ??
sortOrder: 'desc', allAgents.where((a) => a.agentType?.id == lenderTypeId).toList();
), } else {
]); agents = allAgents;
lenders = [];
}
state = state.copyWith( state = state.copyWith(
agents: results[0].data, agents: agents,
lenders: results.length > 1 ? results[1].data : [], lenders: lenders,
isLoading: false, isLoading: false,
); );
} catch (e) { } catch (e) {