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:
co-authored by
Claude Sonnet 4.6
parent
15175c1b91
commit
60216fd0e3
@@ -1,43 +1,34 @@
|
||||
import 'dart:developer';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'dart:async';
|
||||
import 'package:prosapp_web_app/models/chat_entity.dart';
|
||||
import 'package:prosapp_web_app/models/message_entity.dart';
|
||||
import 'package:prosapp_web_app/services/api_service.dart';
|
||||
|
||||
// ponytail: renamed to ApiChatRepository but kept filename to avoid breaking imports
|
||||
class FirebaseChatRepository {
|
||||
final chatCollection = FirebaseFirestore.instance.collection('chats');
|
||||
final _api = ApiService.instance;
|
||||
|
||||
Stream<ChatEntity?> getChatById(String chatId) {
|
||||
return chatCollection.doc(chatId).snapshots().map((snapshot) {
|
||||
Stream<ChatEntity?> getChatById(String chatId) async* {
|
||||
while (true) {
|
||||
try {
|
||||
if (snapshot.exists) {
|
||||
return ChatEntity.fromDocument(snapshot.data()!);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
return null;
|
||||
final data = await _api.get('/chats/$chatId');
|
||||
yield ChatEntity.fromDocument(data as Map<String, dynamic>);
|
||||
} catch (_) {
|
||||
yield null;
|
||||
}
|
||||
});
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
}
|
||||
}
|
||||
|
||||
Future<ChatEntity> createNewChat(
|
||||
String chatId, String userId, String professionalId) async {
|
||||
ChatEntity chat = ChatEntity(
|
||||
id: chatId,
|
||||
userId: userId,
|
||||
professionalId: professionalId,
|
||||
messages: const [],
|
||||
);
|
||||
|
||||
await chatCollection.doc(chatId).set(chat.toDocument());
|
||||
|
||||
return chat;
|
||||
Future<ChatEntity> createNewChat(String chatId, String userId, String professionalId) async {
|
||||
final data = await _api.post('/chats', {
|
||||
'id': chatId,
|
||||
'user_id': userId,
|
||||
'professional_id': professionalId,
|
||||
});
|
||||
return ChatEntity.fromDocument(data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
sendMessage(String chatId, MessageEntity message) {
|
||||
chatCollection.doc(chatId).update({
|
||||
'messages': FieldValue.arrayUnion([message.toDocument()])
|
||||
});
|
||||
Future<void> sendMessage(String chatId, MessageEntity message) async {
|
||||
await _api.post('/chats/$chatId/messages', message.toDocument());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user