Refactor event type handling and add data management page (options and event types)
This commit is contained in:
@@ -1,32 +1,30 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class EventType {
|
||||
class EventTypeModel {
|
||||
final String id;
|
||||
final String name;
|
||||
final double defaultPrice;
|
||||
final DateTime createdAt;
|
||||
|
||||
EventType({
|
||||
EventTypeModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.defaultPrice,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory EventType.fromFirestore(DocumentSnapshot doc) {
|
||||
Map<String, dynamic> data = doc.data() as Map<String, dynamic>;
|
||||
|
||||
double price = 0.0;
|
||||
final priceData = data['defaultPrice'];
|
||||
if (priceData is num) {
|
||||
price = priceData.toDouble();
|
||||
} else if (priceData is String) {
|
||||
price = double.tryParse(priceData.replaceAll(',', '.')) ?? 0.0;
|
||||
}
|
||||
|
||||
return EventType(
|
||||
id: doc.id,
|
||||
name: data['name'] ?? '',
|
||||
defaultPrice: price,
|
||||
factory EventTypeModel.fromMap(Map<String, dynamic> map, String id) {
|
||||
return EventTypeModel(
|
||||
id: id,
|
||||
name: map['name'] ?? '',
|
||||
defaultPrice: (map['defaultPrice'] ?? 0.0).toDouble(),
|
||||
createdAt: map['createdAt']?.toDate() ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'name': name,
|
||||
'defaultPrice': defaultPrice,
|
||||
'createdAt': createdAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
class EventOption {
|
||||
final String id;
|
||||
final String code; // Nouveau champ code
|
||||
final String name;
|
||||
final String details;
|
||||
final double valMin;
|
||||
@@ -9,6 +9,7 @@ class EventOption {
|
||||
|
||||
EventOption({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.details,
|
||||
required this.valMin,
|
||||
@@ -19,6 +20,7 @@ class EventOption {
|
||||
factory EventOption.fromMap(Map<String, dynamic> map, String id) {
|
||||
return EventOption(
|
||||
id: id,
|
||||
code: map['code'] ?? id, // Utilise le code ou l'ID en fallback
|
||||
name: map['name'] ?? '',
|
||||
details: map['details'] ?? '',
|
||||
valMin: (map['valMin'] ?? 0.0).toDouble(),
|
||||
@@ -31,6 +33,7 @@ class EventOption {
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'code': code,
|
||||
'name': name,
|
||||
'details': details,
|
||||
'valMin': valMin,
|
||||
|
||||
Reference in New Issue
Block a user