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:
Van Leemput Dayron
2026-03-13 15:02:23 +01:00
parent 3215a990d1
commit 9b08b2896c
36 changed files with 4731 additions and 2 deletions

View File

@@ -0,0 +1,72 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:travel_mate/models/transport_segment.dart';
/// Service that stores per-trip transport segments locally for offline access.
///
/// Uses `SharedPreferences` keyed by `trip_transport_<tripId>` to keep
/// creation/edit quick without round-trips. Real-time status can later be
/// updated by a background job hitting external APIs.
class TransportService {
/// Loads stored transport segments for [tripId].
Future<List<TransportSegment>> loadSegments(String tripId) async {
final prefs = await SharedPreferences.getInstance();
final raw = prefs.getString(_key(tripId));
if (raw == null) return const [];
try {
return TransportSegment.decodeList(raw);
} catch (_) {
await prefs.remove(_key(tripId));
return const [];
}
}
/// Persists the full list of segments for [tripId].
Future<void> saveSegments(
String tripId,
List<TransportSegment> segments,
) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_key(tripId), TransportSegment.encodeList(segments));
}
/// Adds a segment entry.
Future<List<TransportSegment>> addSegment(
String tripId,
TransportSegment segment,
) async {
final current = await loadSegments(tripId);
final updated = [...current, segment];
await saveSegments(tripId, updated);
return updated;
}
/// Deletes a segment by [segmentId].
Future<List<TransportSegment>> deleteSegment(
String tripId,
String segmentId,
) async {
final current = await loadSegments(tripId);
final updated = current.where((s) => s.id != segmentId).toList();
await saveSegments(tripId, updated);
return updated;
}
/// Updates the status of a segment (e.g., delayed/boarding/in_air).
Future<List<TransportSegment>> updateStatus(
String tripId,
String segmentId,
String status,
) async {
final current = await loadSegments(tripId);
final updated = current
.map((s) {
if (s.id != segmentId) return s;
return s.copyWith(status: status);
})
.toList(growable: false);
await saveSegments(tripId, updated);
return updated;
}
String _key(String tripId) => 'trip_transport_$tripId';
}