Update: 2026-05-07 22:19:17
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../core/network/dio_client.dart';
|
||||
import '../../../core/utils/app_snackbar.dart';
|
||||
import '../../../core/utils/logger.dart';
|
||||
|
||||
class CompaniesManagementController extends GetxController {
|
||||
final Dio _dio = DioClient().client;
|
||||
|
||||
var isLoading = true.obs;
|
||||
var companies = <Map<String, dynamic>>[].obs;
|
||||
var employees = <Map<String, dynamic>>[].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchCompanies();
|
||||
}
|
||||
|
||||
Future<void> fetchCompanies() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response = await _dio.get('companies');
|
||||
if (response.data['success'] == true) {
|
||||
companies.value = List<Map<String, dynamic>>.from(response.data['data']);
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to fetch companies', e);
|
||||
AppSnackbar.showError('خطأ', 'تعذر تحميل قائمة الشركات');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteCompany(String id) async {
|
||||
try {
|
||||
final response = await _dio.delete('companies/$id');
|
||||
if (response.data['success'] == true) {
|
||||
companies.removeWhere((c) => c['id'] == id);
|
||||
AppSnackbar.showSuccess('نجاح', 'تم حذف الشركة بنجاح');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to delete company', e);
|
||||
AppSnackbar.showError('خطأ', 'تعذر حذف الشركة');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user