Refactor event type handling and add data management page (options and event types)

This commit is contained in:
ElPoyo
2025-10-15 19:01:09 +02:00
parent f10a608801
commit 5057bf9a77
16 changed files with 1561 additions and 61 deletions

View File

@@ -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,
};
}
}

View File

@@ -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,