citas
This commit is contained in:
@@ -4,15 +4,76 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
|
||||
class EventoService {
|
||||
Future<void> createEvent(String title, String description, String day) async {
|
||||
Future<void> 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<List<Event>> getByProId() async {
|
||||
try {
|
||||
var snapshot = await FirebaseFirestore.instance
|
||||
.collection('services')
|
||||
.where('profesional_id', isEqualTo: uid)
|
||||
.get();
|
||||
|
||||
List<Event> eventos = [];
|
||||
for (var element in snapshot.docs) {
|
||||
eventos.add(Event.fromJson(element.data()));
|
||||
}
|
||||
print('Error getByProId $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<String, dynamic> json) {
|
||||
return Event(
|
||||
title: json['title'],
|
||||
description: json['description'],
|
||||
day: json['day'],
|
||||
range1Hour1: json['range1Hour1'],
|
||||
range1Hour2: json['range1Hour2'],
|
||||
profesionalId: json['profesional_id'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user