Deploy: 2026-05-25 00:29:42
This commit is contained in:
@@ -6,6 +6,7 @@ import 'models/contact_model.dart';
|
||||
import 'models/plan_model.dart';
|
||||
import 'models/super_admin_stats_model.dart';
|
||||
import 'models/whatsapp_status_model.dart';
|
||||
import 'models/meta_session_model.dart';
|
||||
|
||||
class DashboardRepository {
|
||||
final ApiService _apiService = ApiService();
|
||||
@@ -157,4 +158,42 @@ class DashboardRepository {
|
||||
throw Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
// English: Load connected Meta sessions.
|
||||
Future<List<MetaSessionModel>> getMetaSessions() async {
|
||||
final token = await _getToken();
|
||||
final response = await _apiService.getMetaSessions(token);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final list = decoded['data'] as List<dynamic>? ?? [];
|
||||
return list.map((item) => MetaSessionModel.fromJson(item as Map<String, dynamic>)).toList();
|
||||
} else {
|
||||
throw Exception('فشل في جلب جلسات ميتا المتصلة');
|
||||
}
|
||||
}
|
||||
|
||||
// English: Connect a new Facebook Page or Instagram channel.
|
||||
Future<void> connectMetaSession(String channelType, String pageId, String pageName, String pageAccessToken) async {
|
||||
final token = await _getToken();
|
||||
final response = await _apiService.connectMetaSession(token, channelType, pageId, pageName, pageAccessToken);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final error = decoded['message'] as String? ?? 'فشل في ربط القناة';
|
||||
throw Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
// English: Disconnect a Meta page or Instagram channel.
|
||||
Future<void> disconnectMetaSession(int sessionId) async {
|
||||
final token = await _getToken();
|
||||
final response = await _apiService.disconnectMetaSession(token, sessionId);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final error = decoded['message'] as String? ?? 'فشل في قطع اتصال القناة';
|
||||
throw Exception(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// English: Model representing a connected Meta session (Facebook Page or Instagram Business Profile)
|
||||
class MetaSessionModel {
|
||||
final int id;
|
||||
final int companyId;
|
||||
final String channelType;
|
||||
final String pageId;
|
||||
final String pageName;
|
||||
final String status;
|
||||
final String? createdAt;
|
||||
final String? updatedAt;
|
||||
|
||||
MetaSessionModel({
|
||||
required this.id,
|
||||
required this.companyId,
|
||||
required this.channelType,
|
||||
required this.pageId,
|
||||
required this.pageName,
|
||||
required this.status,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
factory MetaSessionModel.fromJson(Map<String, dynamic> json) {
|
||||
return MetaSessionModel(
|
||||
id: json['id'] as int,
|
||||
companyId: json['company_id'] as int,
|
||||
channelType: json['channel_type'] as String,
|
||||
pageId: json['page_id'] as String,
|
||||
pageName: json['page_name'] as String,
|
||||
status: json['status'] as String,
|
||||
createdAt: json['created_at'] as String?,
|
||||
updatedAt: json['updated_at'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'company_id': companyId,
|
||||
'channel_type': channelType,
|
||||
'page_id': pageId,
|
||||
'page_name': pageName,
|
||||
'status': status,
|
||||
'created_at': createdAt,
|
||||
'updated_at': updatedAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user