From dbc0bf0c22370359457c0920d0e97c4b5d90982b Mon Sep 17 00:00:00 2001 From: venbaittech Date: Thu, 22 May 2025 09:20:25 +0530 Subject: [PATCH] apiService merge --- lib/services/apiService.dart | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/services/apiService.dart b/lib/services/apiService.dart index a7fb98c..b4617dc 100644 --- a/lib/services/apiService.dart +++ b/lib/services/apiService.dart @@ -44,6 +44,41 @@ class ApiService { } } + Future> 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> fetchUsers() async { String? ordId = await getOrgId(); final String apiUrlData = '$apiUrl/api/users?org_id=$ordId';