apiService merge

This commit is contained in:
venbaittech 2025-05-22 09:20:25 +05:30
parent 3be2f695c6
commit dbc0bf0c22

View File

@ -44,6 +44,41 @@ class ApiService {
}
}
Future<List<dynamic>> fetchHotelsList() async {
final String apiUrldata = '$apiUrl/api/getHotels';
final token = await getToken();
if (token == null) {
throw Exception('Token not found. Please log in.');
}
final response = await http.get(
Uri.parse(apiUrldata),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
},
);
if (response.statusCode == 200) {
try {
final data = json.decode(response.body);
print("Hotelss - $data");
if (!data.containsKey('data') || data['data'] is! List) {
throw Exception(
"Invalid response format: 'data' field is missing or not a List");
}
return data['data'];
} catch (e) {
throw Exception('Error parsing response: $e');
}
} else {
throw Exception('Failed to load country list');
}
}
Future<List<dynamic>> fetchUsers() async {
String? ordId = await getOrgId();
final String apiUrlData = '$apiUrl/api/users?org_id=$ordId';