services
This commit is contained in:
@@ -91,7 +91,7 @@ class ScheduleEntity extends Equatable {
|
||||
return null;
|
||||
}
|
||||
|
||||
String? getFormatTime(TimeOfDay? time) {
|
||||
static String? getFormatTime(TimeOfDay? time) {
|
||||
if (time == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -53,14 +53,19 @@ class ServiceEntity extends Equatable {
|
||||
day: doc['day'] as String,
|
||||
createdAt: doc['created_at'] as Timestamp,
|
||||
description: doc['description'] as String,
|
||||
range1Hour1: doc['range1_hour1'] as TimeOfDay,
|
||||
range1Hour2: doc['range1_hour2'] as TimeOfDay,
|
||||
range1Hour1: parseTimeOfDay(doc['range1_hour1'] as String),
|
||||
range1Hour2: parseTimeOfDay(doc['range1_hour2'] as String),
|
||||
status: intToEnumService(doc['status'] as int),
|
||||
rate: doc['rate'] as String,
|
||||
location: intToEnum(doc['location'] as int),
|
||||
);
|
||||
}
|
||||
|
||||
static TimeOfDay parseTimeOfDay(String timeString) {
|
||||
final parts = timeString.split(':');
|
||||
return TimeOfDay(hour: int.parse(parts[0]), minute: int.parse(parts[1]));
|
||||
}
|
||||
|
||||
Map<String, dynamic> toDocument() {
|
||||
return {
|
||||
'professional_id': professionalId,
|
||||
@@ -74,14 +79,21 @@ class ServiceEntity extends Equatable {
|
||||
'day': day,
|
||||
'created_at': createdAt,
|
||||
'description': description,
|
||||
'range1_hour1': range1Hour1,
|
||||
'range1_hour2': range1Hour2,
|
||||
'range1_hour1': formatTimeOfDay(range1Hour1),
|
||||
'range1_hour2': formatTimeOfDay(range1Hour2),
|
||||
'rate': rate,
|
||||
'status': enumToIntService(status),
|
||||
'location': enumToInt(location),
|
||||
};
|
||||
}
|
||||
|
||||
String? formatTimeOfDay(TimeOfDay? time) {
|
||||
if (time != null) {
|
||||
return "${time.hour.toString()}:${time.minute.toString()}";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
professionalId,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export 'service_status.dart';
|
||||
|
||||
enum ServiceStatus { pending, active, cancelled, completed }
|
||||
enum ServiceStatus { pending, acepted, active, cancelled, completed }
|
||||
|
||||
int enumToIntService(ServiceStatus state) {
|
||||
return state.index;
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
|
||||
class FirebaseServiceRepository {
|
||||
final serviceCollection = FirebaseFirestore.instance.collection('services');
|
||||
final serviceCollection =
|
||||
FirebaseFirestore.instance.collection('services v2');
|
||||
|
||||
Future<void> createService(ServiceEntity entity) async {
|
||||
log('xd -- ${entity.toString()}');
|
||||
await serviceCollection.add(entity.toDocument());
|
||||
Future<String> createService(ServiceEntity entity) async {
|
||||
DocumentReference<Map<String, dynamic>> docRef =
|
||||
await serviceCollection.add(entity.toDocument());
|
||||
return docRef.id;
|
||||
}
|
||||
|
||||
Stream<ServiceEntity> getService(String serviceId) {
|
||||
return serviceCollection.doc(serviceId).snapshots().map((snapshot) {
|
||||
if (snapshot.exists) {
|
||||
return ServiceEntity.fromDocument(snapshot.data()!);
|
||||
} else {
|
||||
throw Exception('El servicio con ID $serviceId no existe');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateServiceStatus(
|
||||
String serviceId, ServiceStatus newStatus) async {
|
||||
await serviceCollection
|
||||
.doc(serviceId)
|
||||
.update({'status': enumToIntService(newStatus)});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user