44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:get/get.dart';
 | |
| import 'package:marco/helpers/services/api_service.dart';
 | |
| import 'package:marco/helpers/services/app_logger.dart';
 | |
| import 'package:marco/model/tenant/tenant_services_model.dart';
 | |
| 
 | |
| class ServiceController extends GetxController {
 | |
|   List<Service> services = [];
 | |
|   Service? selectedService;
 | |
|   final isLoadingServices = false.obs;
 | |
| 
 | |
|   /// Fetch services assigned to a project
 | |
|   Future<void> fetchServices(String projectId) async {
 | |
|     try {
 | |
|       isLoadingServices.value = true;
 | |
|       final response = await ApiService.getAssignedServices(projectId);
 | |
|       if (response != null) {
 | |
|         services = response.data;
 | |
|         logSafe("Services fetched: ${services.length}");
 | |
|       } else {
 | |
|         logSafe("Failed to fetch services for project $projectId",
 | |
|             level: LogLevel.error);
 | |
|       }
 | |
|     } finally {
 | |
|       isLoadingServices.value = false;
 | |
|       update();
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   /// Select a service
 | |
|   void selectService(Service? service) {
 | |
|     selectedService = service;
 | |
|     update();
 | |
|   }
 | |
| 
 | |
|   /// Clear selection
 | |
|   void clearSelection() {
 | |
|     selectedService = null;
 | |
|     update();
 | |
|   }
 | |
| 
 | |
|   /// Current selected name
 | |
|   String get currentSelection => selectedService?.name ?? "All Services";
 | |
| }
 |