vista
This commit is contained in:
@@ -5,25 +5,48 @@ import 'package:prosappco/src/models/scores_model.dart';
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
|
||||
class EventoService {
|
||||
Future<void> createEvent(String title, String description, String day,
|
||||
String range1Hour1, String range1Hour2, String professionalId) async {
|
||||
Future<String?> createEvent(
|
||||
String title,
|
||||
String description,
|
||||
String day,
|
||||
String range1Hour1,
|
||||
String range1Hour2,
|
||||
String professionalId,
|
||||
String ubicacion,
|
||||
String address,
|
||||
double latitude,
|
||||
double longitude,
|
||||
) async {
|
||||
try {
|
||||
await FirebaseFirestore.instance.collection('services').add({
|
||||
DateTime ahora = DateTime.now();
|
||||
|
||||
final eventId =
|
||||
await FirebaseFirestore.instance.collection('services').add({
|
||||
'user_id': uid,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'day': day,
|
||||
'range1Hour1': range1Hour1,
|
||||
'range1Hour2': range1Hour2,
|
||||
'professional_id': professionalId
|
||||
'professional_id': professionalId,
|
||||
'ubicacion': ubicacion,
|
||||
'address': address,
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'Timestamp': ahora
|
||||
}).then((value) {
|
||||
FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
'services': FieldValue.arrayUnion([value.id])
|
||||
});
|
||||
|
||||
return value.id;
|
||||
});
|
||||
|
||||
return eventId;
|
||||
} catch (e) {
|
||||
print('Evento $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +60,9 @@ Future<List<Event>> getByProId(String day) async {
|
||||
|
||||
List<Event> eventos = [];
|
||||
for (var element in snapshot.docs) {
|
||||
eventos.add(Event.fromJson(element.data()));
|
||||
final event = Event.fromJson(element.data());
|
||||
event.scoresModel = await ScoresModel.scoreTo(event.userId, false, false);
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
@@ -57,8 +82,7 @@ Future<List<Event>> getByProIdAll() async {
|
||||
List<Event> eventos = [];
|
||||
for (var element in snapshot.docs) {
|
||||
final event = Event.fromJson(element.data());
|
||||
event.scoresModel =
|
||||
await ScoresModel.scoreTo(event.userId ?? "", false, false);
|
||||
event.scoresModel = await ScoresModel.scoreTo(event.userId, false, false);
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
@@ -70,23 +94,31 @@ Future<List<Event>> getByProIdAll() async {
|
||||
}
|
||||
|
||||
class Event {
|
||||
String? title;
|
||||
String title;
|
||||
String? description;
|
||||
String? day;
|
||||
String? range1Hour1;
|
||||
String day;
|
||||
String range1Hour1;
|
||||
String? range1Hour2;
|
||||
String? userId;
|
||||
String? professionalId;
|
||||
String userId;
|
||||
String professionalId;
|
||||
String? ubicacion;
|
||||
String? address;
|
||||
double? longitud;
|
||||
double? latitud;
|
||||
ScoresModel? scoresModel;
|
||||
|
||||
Event({
|
||||
this.title,
|
||||
required this.title,
|
||||
this.description,
|
||||
this.day,
|
||||
this.range1Hour1,
|
||||
required this.day,
|
||||
required this.range1Hour1,
|
||||
this.range1Hour2,
|
||||
this.userId,
|
||||
this.professionalId,
|
||||
required this.userId,
|
||||
required this.professionalId,
|
||||
this.ubicacion,
|
||||
this.address,
|
||||
this.longitud,
|
||||
this.latitud,
|
||||
});
|
||||
|
||||
factory Event.fromJson(Map<String, dynamic> json) {
|
||||
@@ -98,9 +130,28 @@ class Event {
|
||||
range1Hour2: json['range1Hour2'],
|
||||
userId: json['user_id'],
|
||||
professionalId: json['professional_id'],
|
||||
ubicacion: json['ubicacion'] ?? '',
|
||||
address: json['address'] ?? '',
|
||||
longitud: json['longitude'] ?? 0,
|
||||
latitud: json['latitude'] ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<Event> getEventById(String uid) async {
|
||||
try {
|
||||
final snapshot = await FirebaseFirestore.instance
|
||||
.collection('services')
|
||||
.doc(uid)
|
||||
.get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
return Event.fromJson(data!);
|
||||
} catch (e) {
|
||||
print('Error getting user: $e');
|
||||
return Event(
|
||||
title: '', day: '', range1Hour1: '', userId: '', professionalId: '');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<Event>> getEventsAllById(String uid) async {
|
||||
try {
|
||||
var snapshot = await FirebaseFirestore.instance
|
||||
|
||||
Reference in New Issue
Block a user