import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:prosappco/src/authentication/authentication_repository.dart'; final uid = AuthenticationRepository.instance.getCurrentUserUid(); class EventoService { Future createEvent( String title, String description, String day, String range1Hour1, String range1Hour2, ) async { try { await FirebaseFirestore.instance.collection('services').add({ 'profesional_id': uid, 'title': title, 'description': description, 'day': day, 'range1Hour1': range1Hour1, 'range1Hour2': range1Hour2 }).then((value) { FirebaseFirestore.instance.collection('users').doc(uid).update({ 'services': FieldValue.arrayUnion([value.id]) }); }); } catch (e) { print('Evento $e'); } } } Future> getByProId(String day) async { try { var snapshot = await FirebaseFirestore.instance .collection('services') .where('profesional_id', isEqualTo: uid) .where('day', isEqualTo: day.toString()) .get(); List eventos = []; for (var element in snapshot.docs) { eventos.add(Event.fromJson(element.data())); } print('eventos $eventos'); return eventos; } catch (e) { print('Error getByProId $e'); return []; } } class Event { String? title; String? description; String? day; String? range1Hour1; String? range1Hour2; String? profesionalId; Event({ this.title, this.description, this.day, this.range1Hour1, this.range1Hour2, this.profesionalId, }); factory Event.fromJson(Map json) { return Event( title: json['title'], description: json['description'], day: json['day'], range1Hour1: json['range1Hour1'], range1Hour2: json['range1Hour2'], profesionalId: json['profesional_id'], ); } static Future> getEventsAllById(String uid) async { try { var snapshot = await FirebaseFirestore.instance .collection('services') .where('profesional_id', isEqualTo: uid) .get(); List eventos = []; for (var element in snapshot.docs) { eventos.add(Event.fromJson(element.data())); } print('eventos $eventos'); return eventos; } catch (e) { print('Error getByProId $e'); return []; } } }