feat: migrate prosappco from Firebase to NestJS REST API (Fase 2)
- Replace all Firebase* repositories with Api* repositories using HTTP + SharedPreferences JWT - Remove Firebase.initializeApp() and firebase_messaging background handler from main.dart - Update DI (app_di.dart) to inject Api* repositories instead of Firebase* ones - Replace all Timestamp/cloud_firestore usage with ISO 8601 String dates - Stub PhoneVerificationService (Firebase phone OTP → backend OTP when implemented) - Add ApiService singleton with JWT management in lib/services/ - Legacy firebase_*_repository.dart files preserved for Fase 4 cleanup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
726cf12fd2
commit
733384091c
@@ -0,0 +1,72 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:setting_repository/src/entities/entities.dart';
|
||||
import 'package:setting_repository/src/repositories/setting_repo.dart';
|
||||
|
||||
const _base = 'https://backend.prosapp.co/api/v1';
|
||||
|
||||
class ApiSettingRepository implements SettingRepository {
|
||||
Future<String?> _getToken() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString('token');
|
||||
}
|
||||
|
||||
Future<Map<String, String>> _headers() async {
|
||||
final t = await _getToken();
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
if (t != null) 'Authorization': 'Bearer $t',
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SettingEntity> getSettings() async {
|
||||
try {
|
||||
final res = await http.get(
|
||||
Uri.parse('$_base/settings'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
final data = jsonDecode(res.body);
|
||||
|
||||
// Backend returns {key: string, value: any}[] or a flat map
|
||||
Map<String, dynamic> doc = {};
|
||||
if (data is List) {
|
||||
for (final entry in data) {
|
||||
if (entry is Map) {
|
||||
final key = entry['key']?.toString();
|
||||
final value = entry['value'];
|
||||
if (key != null) doc[key] = value;
|
||||
}
|
||||
}
|
||||
} else if (data is Map) {
|
||||
doc = Map<String, dynamic>.from(data);
|
||||
}
|
||||
|
||||
return SettingEntity.fromDocument(doc);
|
||||
} catch (_) {
|
||||
// Return safe defaults if settings call fails
|
||||
return const SettingEntity(
|
||||
tarifas: null,
|
||||
domicilios: null,
|
||||
google: null,
|
||||
versionIos: null,
|
||||
versionAndroid: null,
|
||||
horaNotificacion: null,
|
||||
tituloSoporte: null,
|
||||
parrafoSoporte: null,
|
||||
numeroSoporte: null,
|
||||
emailSoporte: null,
|
||||
diasSoporte: null,
|
||||
horasSoporte: null,
|
||||
politicasPrivacidad: null,
|
||||
politicasPrivacidadTitle: null,
|
||||
politicasPrivacidadBody: null,
|
||||
terminosCondiciones: null,
|
||||
terminosCondicionesTitle: null,
|
||||
terminosCondicionesBody: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user