feat: Add services for managing trip-related data
- Implement EmergencyService for handling emergency contacts per trip. - Create GuestFlagService to manage guest mode flags for trips. - Introduce NotificationService with local notification capabilities. - Add OfflineFlagService for managing offline caching flags. - Develop PackingService for shared packing lists per trip. - Implement ReminderService for managing reminders/to-dos per trip. - Create SosService for dispatching SOS events to a backend. - Add StorageService with album image upload functionality. - Implement TransportService for managing transport segments per trip. - Create TripChecklistService for storing and retrieving trip checklists. - Add TripDocumentService for persisting trip documents metadata. test: Add unit tests for new services - Implement tests for AlbumService, BudgetService, EmergencyService, GuestFlagService, PackingService, ReminderService, SosService, TransportService, TripChecklistService, and TripDocumentService. - Ensure tests cover adding, loading, deleting, and handling corrupted payloads for each service.
This commit is contained in:
59
lib/services/ai_activity_service.dart
Normal file
59
lib/services/ai_activity_service.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
/// Provides AI-powered activity suggestions using an external endpoint.
|
||||
///
|
||||
/// The endpoint is expected to accept POST JSON:
|
||||
/// { "city": "...", "interests": ["food","art"], "budget": "low|mid|high" }
|
||||
/// and return { "suggestions": [ { "title": "...", "detail": "..." }, ... ] }
|
||||
///
|
||||
/// This class is a thin client and can be wired to a custom backend that
|
||||
/// proxies LLM calls (to avoid shipping secrets in the app).
|
||||
class AiActivityService {
|
||||
/// Base URL of the AI suggestion endpoint.
|
||||
final String baseUrl;
|
||||
|
||||
/// Optional API key if your backend requires it.
|
||||
final String? apiKey;
|
||||
|
||||
/// Creates an AI activity service client.
|
||||
const AiActivityService({required this.baseUrl, this.apiKey});
|
||||
|
||||
/// Fetches suggestions for the given [city] with optional [interests] and [budget].
|
||||
///
|
||||
/// Returns a list of string suggestions. In case of error, returns an empty list
|
||||
/// to keep the UI responsive.
|
||||
Future<List<String>> fetchSuggestions({
|
||||
required String city,
|
||||
List<String> interests = const [],
|
||||
String budget = 'mid',
|
||||
}) async {
|
||||
final uri = Uri.parse('$baseUrl/ai/suggestions');
|
||||
try {
|
||||
final response = await http.post(
|
||||
uri,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
if (apiKey != null) 'Authorization': 'Bearer $apiKey',
|
||||
},
|
||||
body: json.encode({
|
||||
'city': city,
|
||||
'interests': interests,
|
||||
'budget': budget,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body) as Map<String, dynamic>;
|
||||
final list = (data['suggestions'] as List<dynamic>? ?? [])
|
||||
.cast<Map<String, dynamic>>();
|
||||
return list
|
||||
.map((item) => item['title'] as String? ?? 'Suggestion')
|
||||
.toList();
|
||||
}
|
||||
return const [];
|
||||
} catch (_) {
|
||||
return const [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user