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,179 @@
import 'dart:convert';
/// Represents a transport segment (vol/train/bus) tied to a trip.
///
/// Includes identifiers (PNR/train number), schedule times, status, carrier
/// and station/airport codes for display and potential real-time tracking.
class TransportSegment {
/// Unique identifier for this segment entry.
final String id;
/// Segment type: `flight`, `train`, `bus` (extendable).
final String type;
/// Carrier code (e.g., AF, SN, TGV, OUIGO).
final String carrier;
/// Public number (e.g., AF763, TGV 8401).
final String number;
/// Booking reference / PNR if available.
final String? pnr;
/// Departure code (IATA/CRS) or station name.
final String departureCode;
/// Arrival code (IATA/CRS) or station name.
final String arrivalCode;
/// Planned departure time (UTC).
final DateTime departureUtc;
/// Planned arrival time (UTC).
final DateTime arrivalUtc;
/// Current status string (scheduled/delayed/cancelled/boarding/in_air etc.).
final String status;
/// Gate/platform when known.
final String? gate;
/// Seat assignment if provided.
final String? seat;
/// Created-at timestamp for ordering.
final DateTime createdAt;
/// Creates a transport segment entry.
const TransportSegment({
required this.id,
required this.type,
required this.carrier,
required this.number,
required this.departureCode,
required this.arrivalCode,
required this.departureUtc,
required this.arrivalUtc,
required this.status,
required this.createdAt,
this.pnr,
this.gate,
this.seat,
});
/// Helper to instantiate a new scheduled segment with defaults.
factory TransportSegment.newSegment({
required String id,
required String type,
required String carrier,
required String number,
required String departureCode,
required String arrivalCode,
required DateTime departureUtc,
required DateTime arrivalUtc,
String? pnr,
String? gate,
String? seat,
}) {
return TransportSegment(
id: id,
type: type,
carrier: carrier,
number: number,
pnr: pnr,
departureCode: departureCode,
arrivalCode: arrivalCode,
departureUtc: departureUtc,
arrivalUtc: arrivalUtc,
gate: gate,
seat: seat,
status: 'scheduled',
createdAt: DateTime.now().toUtc(),
);
}
/// Returns a copy with updated fields.
TransportSegment copyWith({
String? id,
String? type,
String? carrier,
String? number,
String? pnr,
String? departureCode,
String? arrivalCode,
DateTime? departureUtc,
DateTime? arrivalUtc,
String? status,
String? gate,
String? seat,
DateTime? createdAt,
}) {
return TransportSegment(
id: id ?? this.id,
type: type ?? this.type,
carrier: carrier ?? this.carrier,
number: number ?? this.number,
pnr: pnr ?? this.pnr,
departureCode: departureCode ?? this.departureCode,
arrivalCode: arrivalCode ?? this.arrivalCode,
departureUtc: departureUtc ?? this.departureUtc,
arrivalUtc: arrivalUtc ?? this.arrivalUtc,
status: status ?? this.status,
gate: gate ?? this.gate,
seat: seat ?? this.seat,
createdAt: createdAt ?? this.createdAt,
);
}
/// Serializes the segment to JSON for persistence.
Map<String, dynamic> toJson() {
return {
'id': id,
'type': type,
'carrier': carrier,
'number': number,
'pnr': pnr,
'departureCode': departureCode,
'arrivalCode': arrivalCode,
'departureUtc': departureUtc.toIso8601String(),
'arrivalUtc': arrivalUtc.toIso8601String(),
'status': status,
'gate': gate,
'seat': seat,
'createdAt': createdAt.toIso8601String(),
};
}
/// Deserializes a segment from JSON.
factory TransportSegment.fromJson(Map<String, dynamic> json) {
return TransportSegment(
id: json['id'] as String,
type: json['type'] as String,
carrier: json['carrier'] as String,
number: json['number'] as String,
pnr: json['pnr'] as String?,
departureCode: json['departureCode'] as String,
arrivalCode: json['arrivalCode'] as String,
departureUtc: DateTime.parse(json['departureUtc'] as String),
arrivalUtc: DateTime.parse(json['arrivalUtc'] as String),
status: json['status'] as String,
gate: json['gate'] as String?,
seat: json['seat'] as String?,
createdAt: DateTime.parse(json['createdAt'] as String),
);
}
/// Encodes a list of segments to JSON string.
static String encodeList(List<TransportSegment> segments) {
return json.encode(segments.map((s) => s.toJson()).toList());
}
/// Decodes a list of segments from JSON string.
static List<TransportSegment> decodeList(String raw) {
final decoded = json.decode(raw) as List<dynamic>;
return decoded
.cast<Map<String, dynamic>>()
.map(TransportSegment.fromJson)
.toList();
}
}