servicio
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:service_repository/service_repository.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ServiceEntity extends Equatable {
|
||||
final String? id;
|
||||
final String professionalId;
|
||||
final bool professionalScored;
|
||||
final String userId;
|
||||
@@ -22,6 +23,7 @@ class ServiceEntity extends Equatable {
|
||||
final ServiceLocationPreferences location;
|
||||
|
||||
const ServiceEntity({
|
||||
this.id,
|
||||
required this.professionalId,
|
||||
required this.professionalScored,
|
||||
required this.userId,
|
||||
@@ -40,8 +42,9 @@ class ServiceEntity extends Equatable {
|
||||
required this.location,
|
||||
});
|
||||
|
||||
static ServiceEntity fromDocument(Map<String, dynamic> doc) {
|
||||
static ServiceEntity fromDocument(Map<String, dynamic> doc, String id) {
|
||||
return ServiceEntity(
|
||||
id: id,
|
||||
professionalId: doc['professional_id'] as String,
|
||||
professionalScored: doc['professional_scored'] as bool,
|
||||
userId: doc['user_id'] as String,
|
||||
@@ -68,6 +71,7 @@ class ServiceEntity extends Equatable {
|
||||
|
||||
Map<String, dynamic> toDocument() {
|
||||
return {
|
||||
'id': id,
|
||||
'professional_id': professionalId,
|
||||
'professional_scored': professionalScored,
|
||||
'user_id': userId,
|
||||
@@ -95,7 +99,8 @@ class ServiceEntity extends Equatable {
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
professionalId,
|
||||
professionalScored,
|
||||
userId,
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
export 'service_status.dart';
|
||||
|
||||
enum ServiceStatus { pending, acepted, active, cancelled, completed }
|
||||
enum ServiceStatus {
|
||||
pending, // 0
|
||||
acepted, // 1
|
||||
denied, // 2
|
||||
active, // 3
|
||||
cancelled, // 4
|
||||
completed, // 5
|
||||
}
|
||||
|
||||
int enumToIntService(ServiceStatus state) {
|
||||
return state.index;
|
||||
|
||||
@@ -21,7 +21,7 @@ class FirebaseServiceRepository {
|
||||
Stream<ServiceEntity> getService(String serviceId) {
|
||||
return serviceCollection.doc(serviceId).snapshots().map((snapshot) {
|
||||
if (snapshot.exists) {
|
||||
return ServiceEntity.fromDocument(snapshot.data()!);
|
||||
return ServiceEntity.fromDocument(snapshot.data()!, snapshot.id);
|
||||
} else {
|
||||
throw Exception('El servicio con ID $serviceId no existe');
|
||||
}
|
||||
@@ -31,10 +31,10 @@ class FirebaseServiceRepository {
|
||||
Stream<List<ServiceEntity>> getServicesForUser(String userId) {
|
||||
return serviceCollection
|
||||
.where('user_id', isEqualTo: userId)
|
||||
.where('status', whereIn: [0, 1, 2])
|
||||
.where('status', whereIn: [0, 1, 2, 3])
|
||||
.snapshots()
|
||||
.map((querySnapshot) => querySnapshot.docs
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data()))
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data(), doc.id))
|
||||
.toList());
|
||||
}
|
||||
|
||||
@@ -42,20 +42,20 @@ class FirebaseServiceRepository {
|
||||
String professionalId) {
|
||||
return serviceCollection
|
||||
.where('professional_id', isEqualTo: professionalId)
|
||||
.where('status', whereIn: [0, 1, 2])
|
||||
.where('status', whereIn: [0, 1, 2, 3])
|
||||
.snapshots()
|
||||
.map((querySnapshot) => querySnapshot.docs
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data()))
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data(), doc.id))
|
||||
.toList());
|
||||
}
|
||||
|
||||
Stream<List<ServiceEntity>> getServicesHistoryForUser(String userId) {
|
||||
return serviceCollection
|
||||
.where('user_id', isEqualTo: userId)
|
||||
.where('status', whereIn: [3, 4])
|
||||
.where('status', whereIn: [4, 5])
|
||||
.snapshots()
|
||||
.map((querySnapshot) => querySnapshot.docs
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data()))
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data(), doc.id))
|
||||
.toList());
|
||||
}
|
||||
|
||||
@@ -63,10 +63,18 @@ class FirebaseServiceRepository {
|
||||
String professionalId) {
|
||||
return serviceCollection
|
||||
.where('professional_id', isEqualTo: professionalId)
|
||||
.where('status', whereIn: [3, 4])
|
||||
.where('status', whereIn: [4, 5])
|
||||
.snapshots()
|
||||
.map((querySnapshot) => querySnapshot.docs
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data()))
|
||||
.map((doc) => ServiceEntity.fromDocument(doc.data(), doc.id))
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 0 - pending
|
||||
// 1 - acepted
|
||||
// 2 - denied
|
||||
// 3 - active
|
||||
// 4 - cancelled
|
||||
// 5 - completed
|
||||
Reference in New Issue
Block a user