feat: implement ExperienceAdapter and update ExperienceRepositoryImpl to use Data Connect and FirebaseAuth
This commit is contained in:
@@ -81,3 +81,4 @@ export 'src/entities/availability/day_availability.dart';
|
||||
|
||||
// Adapters
|
||||
export 'src/adapters/profile/emergency_contact_adapter.dart';
|
||||
export 'src/adapters/profile/experience_adapter.dart';
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Adapter for Experience data (skills/industries) to map data layer values to domain models.
|
||||
class ExperienceAdapter {
|
||||
/// Converts a dynamic list (from backend AnyValue) to List<String>.
|
||||
///
|
||||
/// Handles nulls and converts elements to Strings.
|
||||
static List<String> fromDynamicList(dynamic data) {
|
||||
if (data == null) return [];
|
||||
|
||||
if (data is List) {
|
||||
return data
|
||||
.where((e) => e != null)
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
}
|
||||
|
||||
// In case it comes as a map or single value, we treat it as empty or single?
|
||||
// Safer to just return empty if not a list for now.
|
||||
debugPrint('ExperienceAdapter: Expected List but got ${data.runtimeType}');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,40 @@
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:firebase_data_connect/firebase_data_connect.dart' as fdc;
|
||||
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../domain/repositories/experience_repository_interface.dart';
|
||||
|
||||
/// Implementation of [ExperienceRepositoryInterface] that delegates to Data Connect.
|
||||
class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
|
||||
final ProfileRepositoryMock _mockRepository;
|
||||
final dc.ExampleConnector _dataConnect;
|
||||
// ignore: unused_field
|
||||
final FirebaseAuth _firebaseAuth;
|
||||
|
||||
/// Creates a [ExperienceRepositoryImpl] with the given [ProfileRepositoryMock].
|
||||
ExperienceRepositoryImpl(this._mockRepository);
|
||||
/// Creates a [ExperienceRepositoryImpl] using Data Connect and Auth.
|
||||
ExperienceRepositoryImpl({
|
||||
required dc.ExampleConnector dataConnect,
|
||||
required FirebaseAuth firebaseAuth,
|
||||
}) : _dataConnect = dataConnect,
|
||||
_firebaseAuth = firebaseAuth;
|
||||
|
||||
@override
|
||||
Future<List<String>> getIndustries(String staffId) {
|
||||
return _mockRepository.getStaffIndustries(staffId);
|
||||
Future<dc.GetStaffByIdStaff> _getStaff(String staffId) async {
|
||||
final result = await _dataConnect.getStaffById(id: staffId).execute();
|
||||
if (result.data.staff == null) {
|
||||
throw Exception('Staff profile not found');
|
||||
}
|
||||
return result.data.staff!;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<String>> getSkills(String staffId) {
|
||||
return _mockRepository.getStaffSkills(staffId);
|
||||
Future<List<String>> getIndustries(String staffId) async {
|
||||
final staff = await _getStaff(staffId);
|
||||
return ExperienceAdapter.fromDynamicList(staff.industries?.value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<String>> getSkills(String staffId) async {
|
||||
final staff = await _getStaff(staffId);
|
||||
return ExperienceAdapter.fromDynamicList(staff.skills?.value);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -23,7 +42,11 @@ class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
|
||||
String staffId,
|
||||
List<String> industries,
|
||||
List<String> skills,
|
||||
) {
|
||||
return _mockRepository.saveExperience(staffId, industries, skills);
|
||||
) async {
|
||||
await _dataConnect
|
||||
.updateStaff(id: staffId)
|
||||
.industries(fdc.AnyValue(industries))
|
||||
.skills(fdc.AnyValue(skills))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
library staff_profile_experience;
|
||||
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
|
||||
@@ -21,7 +22,10 @@ class StaffProfileExperienceModule extends Module {
|
||||
void binds(Injector i) {
|
||||
// Repository
|
||||
i.addLazySingleton<ExperienceRepositoryInterface>(
|
||||
() => ExperienceRepositoryImpl(i.get<ProfileRepositoryMock>()),
|
||||
() => ExperienceRepositoryImpl(
|
||||
dataConnect: ExampleConnector.instance,
|
||||
firebaseAuth: FirebaseAuth.instance,
|
||||
),
|
||||
);
|
||||
|
||||
// UseCases
|
||||
|
||||
@@ -22,6 +22,7 @@ dependencies:
|
||||
path: ../../../../../../core
|
||||
krow_data_connect:
|
||||
path: ../../../../../../data_connect
|
||||
firebase_auth: ^5.0.0
|
||||
design_system:
|
||||
path: ../../../../../../design_system
|
||||
core_localization:
|
||||
|
||||
Reference in New Issue
Block a user