feat: Implement messaging functionality with conversation and chat screens, and enhance agent detail views.
This commit is contained in:
@@ -108,6 +108,93 @@ class AgentsRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get agent by ID: GET /agents/{id}
|
||||
/// Response: { success, data: AgentProfile }
|
||||
Future<AgentProfile> getAgentById(String id) async {
|
||||
try {
|
||||
final response = await _dio.get('${ApiConstants.agents}/$id');
|
||||
final data = response.data['data'] as Map<String, dynamic>;
|
||||
return AgentProfile.fromJson(data);
|
||||
} on DioException catch (e) {
|
||||
if (e.error is ApiException) throw e.error as ApiException;
|
||||
throw ApiException(
|
||||
message: e.message ?? 'Failed to fetch agent',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get field values for agent: GET /agents/{id}/field-values
|
||||
/// Response: { success, data: { agentProfileId, fieldValues: [...] } }
|
||||
Future<List<AgentFieldValue>> getFieldValues(String agentId) async {
|
||||
try {
|
||||
final response =
|
||||
await _dio.get('${ApiConstants.agents}/$agentId/field-values');
|
||||
final data = response.data['data'] as Map<String, dynamic>;
|
||||
final fieldValues = data['fieldValues'] as List<dynamic>? ?? [];
|
||||
return fieldValues
|
||||
.map((e) => AgentFieldValue.fromFieldValueResponse(
|
||||
e as Map<String, dynamic>))
|
||||
.toList();
|
||||
} on DioException catch (e) {
|
||||
if (e.error is ApiException) throw e.error as ApiException;
|
||||
throw ApiException(
|
||||
message: e.message ?? 'Failed to fetch field values',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get testimonials for agent: GET /testimonials/agent/{agentProfileId}
|
||||
Future<List<Map<String, dynamic>>> getTestimonials(String agentId,
|
||||
{int limit = 10}) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'${ApiConstants.testimonials}/agent/$agentId',
|
||||
queryParameters: {'limit': limit},
|
||||
);
|
||||
final data = response.data['data'] as List<dynamic>? ?? [];
|
||||
return data.cast<Map<String, dynamic>>();
|
||||
} on DioException catch (_) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// Get connection status: GET /connection-requests/status/{agentProfileId}
|
||||
Future<Map<String, dynamic>?> getConnectionStatus(String agentId) async {
|
||||
try {
|
||||
final response = await _dio
|
||||
.get('${ApiConstants.connectionRequests}/status/$agentId');
|
||||
return response.data['data'] as Map<String, dynamic>?;
|
||||
} on DioException catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Create connection request: POST /connection-requests
|
||||
Future<bool> createConnectionRequest(String agentId,
|
||||
{String? message}) async {
|
||||
try {
|
||||
await _dio.post(ApiConstants.connectionRequests, data: {
|
||||
'agentProfileId': agentId,
|
||||
if (message != null && message.isNotEmpty) 'message': message,
|
||||
});
|
||||
return true;
|
||||
} on DioException catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Cancel connection request: DELETE /connection-requests/{requestId}
|
||||
Future<bool> cancelConnectionRequest(String requestId) async {
|
||||
try {
|
||||
await _dio.delete('${ApiConstants.connectionRequests}/$requestId');
|
||||
return true;
|
||||
} on DioException catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get agent types: GET /agent-types
|
||||
/// Response: { success, data: [...] }
|
||||
Future<List<AgentType>> getAgentTypes() async {
|
||||
|
||||
@@ -19,6 +19,8 @@ class AgentProfile {
|
||||
final bool isVerified;
|
||||
final bool isFeatured;
|
||||
final bool isActive;
|
||||
final bool isAvailable;
|
||||
final String? email;
|
||||
final AgentType? agentType;
|
||||
final AgentUser? user;
|
||||
final List<AgentFieldValue> fieldValues;
|
||||
@@ -46,6 +48,8 @@ class AgentProfile {
|
||||
this.isVerified = false,
|
||||
this.isFeatured = false,
|
||||
this.isActive = true,
|
||||
this.isAvailable = false,
|
||||
this.email,
|
||||
this.agentType,
|
||||
this.user,
|
||||
this.fieldValues = const [],
|
||||
@@ -212,6 +216,8 @@ class AgentProfile {
|
||||
isVerified: json['isVerified'] as bool? ?? false,
|
||||
isFeatured: json['isFeatured'] as bool? ?? false,
|
||||
isActive: json['isActive'] as bool? ?? true,
|
||||
isAvailable: json['isAvailable'] as bool? ?? false,
|
||||
email: json['email'] as String?,
|
||||
agentType: json['agentType'] != null
|
||||
? AgentType.fromJson(json['agentType'] as Map<String, dynamic>)
|
||||
: null,
|
||||
@@ -264,6 +270,8 @@ class AgentFieldValue {
|
||||
final String fieldSlug;
|
||||
final String fieldName;
|
||||
final String fieldType;
|
||||
final String? sectionSlug;
|
||||
final String? sectionName;
|
||||
final String? textValue;
|
||||
final num? numberValue;
|
||||
final bool? booleanValue;
|
||||
@@ -275,6 +283,8 @@ class AgentFieldValue {
|
||||
required this.fieldSlug,
|
||||
required this.fieldName,
|
||||
required this.fieldType,
|
||||
this.sectionSlug,
|
||||
this.sectionName,
|
||||
this.textValue,
|
||||
this.numberValue,
|
||||
this.booleanValue,
|
||||
@@ -282,6 +292,39 @@ class AgentFieldValue {
|
||||
this.dateValue,
|
||||
});
|
||||
|
||||
/// Parse from the /agents/{id}/field-values endpoint format
|
||||
/// which has { fieldSlug, fieldName, fieldType, sectionSlug, value }
|
||||
factory AgentFieldValue.fromFieldValueResponse(Map<String, dynamic> json) {
|
||||
final value = json['value'];
|
||||
String? textValue;
|
||||
num? numberValue;
|
||||
bool? booleanValue;
|
||||
dynamic jsonValue;
|
||||
|
||||
if (value is String) {
|
||||
textValue = value;
|
||||
} else if (value is num) {
|
||||
numberValue = value;
|
||||
} else if (value is bool) {
|
||||
booleanValue = value;
|
||||
} else if (value is List || value is Map) {
|
||||
jsonValue = value;
|
||||
}
|
||||
|
||||
return AgentFieldValue(
|
||||
id: '',
|
||||
fieldSlug: json['fieldSlug'] as String? ?? '',
|
||||
fieldName: json['fieldName'] as String? ?? '',
|
||||
fieldType: json['fieldType'] as String? ?? '',
|
||||
sectionSlug: json['sectionSlug'] as String?,
|
||||
sectionName: json['sectionName'] as String?,
|
||||
textValue: textValue,
|
||||
numberValue: numberValue,
|
||||
booleanValue: booleanValue,
|
||||
jsonValue: jsonValue,
|
||||
);
|
||||
}
|
||||
|
||||
factory AgentFieldValue.fromJson(Map<String, dynamic> json) {
|
||||
// API returns field info nested: { field: { slug, name, fieldType } }
|
||||
// Fallback to top-level fieldSlug/fieldName/fieldType for compatibility
|
||||
|
||||
Reference in New Issue
Block a user