feat: Enhance trip creation and management features with user validation, improved error handling, and Firestore integration
This commit is contained in:
@@ -36,17 +36,51 @@ class Trip {
|
||||
title: map['title'] ?? '',
|
||||
description: map['description'] ?? '',
|
||||
location: map['location'] ?? '',
|
||||
startDate: DateTime.fromMillisecondsSinceEpoch(map['startDate']),
|
||||
endDate: DateTime.fromMillisecondsSinceEpoch(map['endDate']),
|
||||
startDate: _parseDateTime(map['startDate']),
|
||||
endDate: _parseDateTime(map['endDate']),
|
||||
budget: map['budget']?.toDouble(),
|
||||
participants: List<String>.from(map['participants'] ?? []),
|
||||
createdBy: map['createdBy'] ?? '',
|
||||
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']),
|
||||
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt']),
|
||||
createdAt: _parseDateTime(map['createdAt']),
|
||||
updatedAt: _parseDateTime(map['updatedAt']),
|
||||
status: map['status'] ?? 'draft',
|
||||
);
|
||||
}
|
||||
|
||||
// Méthode helper pour parser les dates depuis différents formats
|
||||
static DateTime _parseDateTime(dynamic dateValue) {
|
||||
if (dateValue == null) {
|
||||
return DateTime.now();
|
||||
}
|
||||
|
||||
if (dateValue is DateTime) {
|
||||
return dateValue;
|
||||
}
|
||||
|
||||
if (dateValue is String) {
|
||||
try {
|
||||
// Essayer de parser comme ISO 8601
|
||||
return DateTime.parse(dateValue);
|
||||
} catch (e) {
|
||||
print('Erreur parsing date string: $dateValue - $e');
|
||||
return DateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
if (dateValue is int) {
|
||||
try {
|
||||
// Traiter comme millisecondes
|
||||
return DateTime.fromMillisecondsSinceEpoch(dateValue);
|
||||
} catch (e) {
|
||||
print('Erreur parsing date int: $dateValue - $e');
|
||||
return DateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
print('Type de date non supporté: ${dateValue.runtimeType} - $dateValue');
|
||||
return DateTime.now();
|
||||
}
|
||||
|
||||
// Constructeur pour créer un Trip depuis JSON
|
||||
factory Trip.fromJson(String jsonStr) {
|
||||
Map<String, dynamic> map = json.decode(jsonStr);
|
||||
|
||||
Reference in New Issue
Block a user