feat: implement comprehensive Firebase Functions backend for equipment management and migrate core repository services
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import 'package:em2rp/services/api_service.dart';
|
||||
|
||||
/// Repository pour gérer toutes les opérations sur les options et types d'événements.
|
||||
class OptionRepository {
|
||||
final ApiService _apiService;
|
||||
|
||||
OptionRepository(this._apiService);
|
||||
|
||||
/// Récupère toutes les options
|
||||
Future<List<Map<String, dynamic>>> getOptions() async {
|
||||
try {
|
||||
final result = await _apiService.call('getOptions', {});
|
||||
final options = result['options'] as List<dynamic>?;
|
||||
if (options == null) return [];
|
||||
return options.map((e) => e as Map<String, dynamic>).toList();
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la récupération des options: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère tous les types d'événements
|
||||
Future<List<Map<String, dynamic>>> getEventTypes() async {
|
||||
try {
|
||||
final result = await _apiService.call('getEventTypes', {});
|
||||
final eventTypes = result['eventTypes'] as List<dynamic>?;
|
||||
if (eventTypes == null) return [];
|
||||
return eventTypes.map((e) => e as Map<String, dynamic>).toList();
|
||||
} catch (e) {
|
||||
throw Exception(
|
||||
'Erreur lors de la récupération des types d\'événements: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Crée un type d'événement
|
||||
Future<String> createEventType({
|
||||
required String name,
|
||||
required double defaultPrice,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _apiService.call('createEventType', {
|
||||
'name': name,
|
||||
'defaultPrice': defaultPrice,
|
||||
});
|
||||
return result['id'] as String;
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la création du type d\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Met à jour un type d'événement
|
||||
Future<void> updateEventType({
|
||||
required String eventTypeId,
|
||||
String? name,
|
||||
double? defaultPrice,
|
||||
}) async {
|
||||
try {
|
||||
final data = <String, dynamic>{'eventTypeId': eventTypeId};
|
||||
if (name != null) data['name'] = name;
|
||||
if (defaultPrice != null) data['defaultPrice'] = defaultPrice;
|
||||
|
||||
await _apiService.call('updateEventType', data);
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la mise à jour du type d\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Supprime un type d'événement
|
||||
Future<void> deleteEventType(String eventTypeId) async {
|
||||
try {
|
||||
await _apiService.call('deleteEventType', {'eventTypeId': eventTypeId});
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la suppression du type d\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Crée une option
|
||||
Future<String> createOption(String code, Map<String, dynamic> data) async {
|
||||
try {
|
||||
final requestData = {
|
||||
'id': code,
|
||||
'code': code,
|
||||
...data
|
||||
};
|
||||
final result = await _apiService.call('createOption', requestData);
|
||||
return result['id'] as String? ?? code;
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la création de l\'option: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Met à jour une option
|
||||
Future<void> updateOption(String optionId, Map<String, dynamic> data) async {
|
||||
try {
|
||||
final requestData = {'optionId': optionId, 'data': data};
|
||||
await _apiService.call('updateOption', requestData);
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la mise à jour de l\'option: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Supprime une option
|
||||
Future<void> deleteOption(String optionId) async {
|
||||
try {
|
||||
await _apiService.call('deleteOption', {'optionId': optionId});
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la suppression de l\'option: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user