Deploy: 2026-05-24 23:27:32

This commit is contained in:
Hamza-Ayed
2026-05-24 23:27:32 +03:00
parent 2ceffc47d9
commit b20f457eaf
156 changed files with 8308 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
class ApiConstants {
// English: The base URL for the backend API endpoints.
// Arabic: عنوان الرابط الأساسي لنقاط نهاية واجهة برمجة التطبيقات الخلفية.
static const String baseUrl = 'https://nabeh.intaleqapp.com/api';
// English: The endpoint for user login.
// Arabic: نقطة النهاية لتسجيل دخول المستخدم.
static const String loginEndpoint = '/auth/login';
// English: The endpoint for fetching current authenticated user details.
// Arabic: نقطة النهاية لجلب تفاصيل المستخدم الحالي المصادق عليه.
static const String meEndpoint = '/auth/me';
// English: The endpoint for WhatsApp connection status checks.
// Arabic: نقطة النهاية للتحقق من حالة اتصال الواتساب.
static const String whatsappStatusEndpoint = '/whatsapp/status';
// English: The endpoint to request a new WhatsApp QR connection.
// Arabic: نقطة النهاية لطلب اتصال واتساب جديد برمز استجابة سريع.
static const String whatsappQrEndpoint = '/whatsapp/qr';
// English: The endpoint to disconnect an active WhatsApp session.
// Arabic: نقطة النهاية لقطع اتصال جلسة واتساب نشطة.
static const String whatsappDisconnectEndpoint = '/whatsapp/disconnect';
// English: The endpoint to list subscription plans.
// Arabic: نقطة النهاية لعرض قائمة باقات الاشتراك.
static const String plansEndpoint = '/plans';
// English: The endpoint to retrieve the contacts directory.
// Arabic: نقطة النهاية لاسترداد دليل جهات الاتصال.
static const String contactsEndpoint = '/contacts';
// English: The endpoint to manage chatbot auto-reply rules.
// Arabic: نقطة النهاية لإدارة قواعد الرد الآلي للروبوت.
static const String chatbotRulesEndpoint = '/chatbot/rules';
// English: The endpoint for Super Admin platform statistics.
// Arabic: نقطة النهاية لإحصائيات منصة المشرف العام.
static const String adminStatsEndpoint = '/admin/stats';
// English: The endpoint to approve a pending company subscription.
// Arabic: نقطة النهاية للموافقة على اشتراك معلق للشركة.
static const String approveBillingEndpoint = '/admin/companies/approve-billing';
}

View File

@@ -0,0 +1,179 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../constants/api_constants.dart';
class ApiService {
// English: Client instance to perform network requests.
// Arabic: نسخة العميل لإجراء طلبات الشبكة.
final http.Client _client = http.Client();
// English: Perform a login request with email and password parameters.
// Arabic: تنفيذ طلب تسجيل الدخول باستخدام معلمات البريد الإلكتروني وكلمة المرور.
Future<http.Response> login(String email, String password) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.loginEndpoint}');
// English: Send POST request containing JSON body to login endpoint.
// Arabic: إرسال طلب من نوع بوست يحتوي على نص جيسون إلى نقطة تسجيل الدخول.
return await _client.post(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: jsonEncode({
'email': email,
'password': password,
}),
);
}
// English: Fetch current user details by supplying the JWT token.
// Arabic: جلب تفاصيل المستخدم الحالي من خلال توفير رمز التحقق.
Future<http.Response> getMe(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.meEndpoint}');
// English: Send GET request with authorization token header.
// Arabic: إرسال طلب من نوع غيت مع ترويسة رمز التفويض.
return await _client.get(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Fetch WhatsApp connection status.
// Arabic: جلب حالة اتصال الواتساب.
Future<http.Response> getWhatsAppStatus(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.whatsappStatusEndpoint}');
return await _client.get(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Fetch subscription plans list.
// Arabic: جلب قائمة باقات الاشتراك.
Future<http.Response> getPlans(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.plansEndpoint}');
return await _client.get(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Fetch CRM contacts directory.
// Arabic: جلب دليل جهات الاتصال الخاص بنظام إدارة العملاء.
Future<http.Response> getContacts(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.contactsEndpoint}');
return await _client.get(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Create a new contact in CRM directory.
// Arabic: إنشاء جهة اتصال جديدة في دليل إدارة العملاء.
Future<http.Response> addContact(String token, String name, String phone) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.contactsEndpoint}');
return await _client.post(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
body: jsonEncode({
'name': name,
'phone': phone,
}),
);
}
// English: Fetch chatbot rules.
// Arabic: جلب قواعد الرد الآلي لروبوت الدردشة.
Future<http.Response> getChatbotRules(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.chatbotRulesEndpoint}');
return await _client.get(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Fetch Super Admin platform statistics.
// Arabic: جلب إحصائيات منصة المشرف العام.
Future<http.Response> getAdminStats(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.adminStatsEndpoint}');
return await _client.get(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Request a new WhatsApp QR connection.
// Arabic: طلب اتصال واتساب جديد برمز استجابة سريع.
Future<http.Response> requestWhatsAppQr(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.whatsappQrEndpoint}');
return await _client.post(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Disconnect the active WhatsApp connection session.
// Arabic: قطع اتصال جلسة الواتساب النشطة.
Future<http.Response> disconnectWhatsApp(String token) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.whatsappDisconnectEndpoint}');
return await _client.post(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
);
}
// English: Approve a pending company subscription billing.
// Arabic: الموافقة على اشتراك فوترة الشركة المعلق.
Future<http.Response> approveBilling(String token, int companyId) async {
final url = Uri.parse('${ApiConstants.baseUrl}${ApiConstants.approveBillingEndpoint}');
return await _client.post(
url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
},
body: jsonEncode({
'company_id': companyId,
}),
);
}
}

View File

@@ -0,0 +1,29 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class SecureStorageService {
// English: Create an instance of secure storage to write keys safely.
// Arabic: إنشاء نسخة من التخزين الآمن لكتابة المفاتيح بشكل آمن.
final FlutterSecureStorage _storage = const FlutterSecureStorage();
// English: The key used to store the JWT token.
// Arabic: المفتاح المستخدم لتخزين رمز التحقق.
static const String _tokenKey = 'jwt_token';
// English: Write the JWT token to secure storage.
// Arabic: كتابة رمز التحقق في التخزين الآمن.
Future<void> writeToken(String token) async {
await _storage.write(key: _tokenKey, value: token);
}
// English: Read the JWT token from secure storage.
// Arabic: قراءة رمز التحقق من التخزين الآمن.
Future<String?> readToken() async {
return await _storage.read(key: _tokenKey);
}
// English: Delete the JWT token from secure storage when user logs out.
// Arabic: حذف رمز التحقق من التخزين الآمن عند تسجيل خروج المستخدم.
Future<void> deleteToken() async {
await _storage.delete(key: _tokenKey);
}
}