feat: migrate Firebase → NestJS REST API backend

Replace all Firebase SDK (Auth, Firestore, Storage) with HTTP calls
to backend.prosapp.co/api/v1:

- New ApiService singleton (JWT token, GET/POST/PATCH/DELETE/upload)
- auth_provider: Firebase Auth → /auth/login, /auth/register, /auth/phone/*
- services_provider + calendar_services_provider → /services endpoints
- professional_provider + professionals_provider → /professional-info, /users/professionals
- profile_form_provider + professional_form_provider → /users/me, /storage/upload
- cities/professions/settings providers → /cities, /professions, /settings
- firebase_chat_repository → polling via /chats endpoints (3s interval)
- firebase_score_repository → polling via /comments endpoints (10s interval)
- professional_detail_provider → /users/:id + /professional-info/:id
- dashboard_view: Firestore.add → POST /services
- chat_view + rating_view: FirebaseAuth.uid → AuthProvider.user.id
- Models: Timestamp → String for createdAt fields
- google_fonts upgraded to ^8.1.0 (Dart 3.12 compat)
- Remove firebase_core, firebase_auth, cloud_firestore, firebase_storage from pubspec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-18 15:53:39 -05:00
co-authored by Claude Sonnet 4.6
parent 15175c1b91
commit 60216fd0e3
29 changed files with 440 additions and 1304 deletions
+30 -121
View File
@@ -1,18 +1,17 @@
import 'dart:typed_data';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:prosapp_web_app/models/location_preferences.dart';
import 'package:prosapp_web_app/models/payment_method_entity.dart';
import 'package:prosapp_web_app/models/profesional.dart';
import 'package:prosapp_web_app/models/schedules.dart';
import 'package:prosapp_web_app/services/api_service.dart';
import 'package:prosapp_web_app/services/notifications_service.dart';
class ProfessionalFormProvider with ChangeNotifier {
Profesional? profesional;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
GlobalKey<FormState> profileFormKey = GlobalKey<FormState>();
final _api = ApiService.instance;
copyProfesionalWith({
String? id,
@@ -41,160 +40,70 @@ class ProfessionalFormProvider with ChangeNotifier {
profession: profession ?? profesional!.profession,
ratePreferences: ratePreferences,
rate: rate ?? profesional!.rate,
locationPreferences:
locationPreferences ?? profesional!.locationPreferences,
locationPreferences: locationPreferences ?? profesional!.locationPreferences,
bannerPicture: bannerPicture ?? profesional!.bannerPicture,
identificationPicture:
identificationPicture ?? profesional!.identificationPicture,
identificationPicture: identificationPicture ?? profesional!.identificationPicture,
certificatePicture: certificatePicture ?? profesional!.certificatePicture,
latitude: latitude ?? profesional!.latitude,
longitude: longitude ?? profesional!.longitude,
specializations: specializations ?? profesional!.specializations,
specializationsPictures:
specializationsPictures ?? profesional!.specializationsPictures,
specializationsPictures: specializationsPictures ?? profesional!.specializationsPictures,
schedules: schedules ?? profesional!.schedules,
paymentMethods: paymentMethods ?? profesional!.paymentMethods,
);
notifyListeners();
}
bool _validForm() {
return formKey.currentState!.validate();
}
bool _validForm() => formKey.currentState!.validate();
bool _validProfileForm() => profileFormKey.currentState!.validate();
bool _validProfileForm() {
return profileFormKey.currentState!.validate();
}
setProfesional(Profesional profesional) {
this.profesional = profesional;
setProfesional(Profesional p) {
profesional = p;
notifyListeners();
}
Future<bool> updateProfesionalInfo(String userId) async {
if (!_validForm()) return false;
final docProfessional = FirebaseFirestore.instance
.collection('professional_info')
.doc(userId)
.withConverter(
fromFirestore: (snapshot, _) =>
Profesional.fromDocument(snapshot.data()!),
toFirestore: (user, _) => user.toDocument(),
);
await docProfessional.set(profesional!);
await _api.patch('/professional-info/$userId', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<bool> updateProfesionalProfileInfo(String userId) async {
if (!_validProfileForm()) return false;
final docProfessional = FirebaseFirestore.instance
.collection('professional_info')
.doc(userId)
.withConverter(
fromFirestore: (snapshot, _) =>
Profesional.fromDocument(snapshot.data()!),
toFirestore: (user, _) => user.toDocument(),
);
await docProfessional.set(profesional!);
await _api.patch('/professional-info/$userId', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<bool> updateProfesionalProfileScheduleInfo(String userId) async {
final docProfessional = FirebaseFirestore.instance
.collection('professional_info')
.doc(userId)
.withConverter(
fromFirestore: (snapshot, _) =>
Profesional.fromDocument(snapshot.data()!),
toFirestore: (user, _) => user.toDocument(),
);
await docProfessional.set(profesional!);
await _api.patch('/professional-info/$userId', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<Profesional> uploadPdfIdentification(
Uint8List fileBytes, String userId) async {
try {
final storageRef = FirebaseStorage.instance
.ref()
.child('$userId/PDF/${userId}_cedula.pdf');
await storageRef.putData(fileBytes);
final url = await storageRef.getDownloadURL();
copyProfesionalWith(identificationPicture: url);
notifyListeners();
return profesional!;
} catch (e) {
print("Error al subir el PDF de identificación: $e");
NotificationsService.showSnackbar('Error al subir el PDF');
rethrow;
}
Future<Profesional> uploadPdfIdentification(Uint8List fileBytes, String userId) async {
final url = await _api.upload(fileBytes, '${userId}_cedula.pdf');
if (url != null) copyProfesionalWith(identificationPicture: url);
notifyListeners();
return profesional!;
}
Future<Profesional> uploadPdfCertificate(
Uint8List fileBytes, String userId) async {
try {
final storageRef = FirebaseStorage.instance
.ref()
.child('$userId/PDF/${userId}_certificado.pdf');
await storageRef.putData(fileBytes);
final url = await storageRef.getDownloadURL();
copyProfesionalWith(certificatePicture: url);
notifyListeners();
return profesional!;
} catch (e) {
print("Error al subir el PDF de identificación: $e");
NotificationsService.showSnackbar('Error al subir el PDF');
rethrow;
}
Future<Profesional> uploadPdfCertificate(Uint8List fileBytes, String userId) async {
final url = await _api.upload(fileBytes, '${userId}_certificado.pdf');
if (url != null) copyProfesionalWith(certificatePicture: url);
notifyListeners();
return profesional!;
}
Future<Profesional> uploadPdfSpecializations(
List<Uint8List> filesBytes, String userId) async {
try {
List<String> urls = [];
for (int i = 0; i < filesBytes.length; i++) {
final storageRef = FirebaseStorage.instance.ref().child(
'$userId/PDF/${userId}_${DateTime.now().millisecondsSinceEpoch}_especializacion_$i.pdf');
await storageRef.putData(filesBytes[i]);
final url = await storageRef.getDownloadURL();
urls.add(url);
}
copyProfesionalWith(specializationsPictures: urls);
notifyListeners();
return profesional!;
} catch (e) {
print("Error al subir los PDFs de especialización: $e");
NotificationsService.showSnackbar('Error al subir los PDFs');
rethrow;
Future<Profesional> uploadPdfSpecializations(List<Uint8List> filesBytes, String userId) async {
List<String> urls = [];
for (int i = 0; i < filesBytes.length; i++) {
final url = await _api.upload(filesBytes[i], '${userId}_especializacion_$i.pdf');
if (url != null) urls.add(url);
}
copyProfesionalWith(specializationsPictures: urls);
notifyListeners();
return profesional!;
}
}