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
|
// Adapters
|
||||||
export 'src/adapters/profile/emergency_contact_adapter.dart';
|
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';
|
import '../../domain/repositories/experience_repository_interface.dart';
|
||||||
|
|
||||||
/// Implementation of [ExperienceRepositoryInterface] that delegates to Data Connect.
|
/// Implementation of [ExperienceRepositoryInterface] that delegates to Data Connect.
|
||||||
class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
|
class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
|
||||||
final ProfileRepositoryMock _mockRepository;
|
final dc.ExampleConnector _dataConnect;
|
||||||
|
// ignore: unused_field
|
||||||
|
final FirebaseAuth _firebaseAuth;
|
||||||
|
|
||||||
/// Creates a [ExperienceRepositoryImpl] with the given [ProfileRepositoryMock].
|
/// Creates a [ExperienceRepositoryImpl] using Data Connect and Auth.
|
||||||
ExperienceRepositoryImpl(this._mockRepository);
|
ExperienceRepositoryImpl({
|
||||||
|
required dc.ExampleConnector dataConnect,
|
||||||
|
required FirebaseAuth firebaseAuth,
|
||||||
|
}) : _dataConnect = dataConnect,
|
||||||
|
_firebaseAuth = firebaseAuth;
|
||||||
|
|
||||||
@override
|
Future<dc.GetStaffByIdStaff> _getStaff(String staffId) async {
|
||||||
Future<List<String>> getIndustries(String staffId) {
|
final result = await _dataConnect.getStaffById(id: staffId).execute();
|
||||||
return _mockRepository.getStaffIndustries(staffId);
|
if (result.data.staff == null) {
|
||||||
|
throw Exception('Staff profile not found');
|
||||||
|
}
|
||||||
|
return result.data.staff!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<String>> getSkills(String staffId) {
|
Future<List<String>> getIndustries(String staffId) async {
|
||||||
return _mockRepository.getStaffSkills(staffId);
|
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
|
@override
|
||||||
@@ -23,7 +42,11 @@ class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
|
|||||||
String staffId,
|
String staffId,
|
||||||
List<String> industries,
|
List<String> industries,
|
||||||
List<String> skills,
|
List<String> skills,
|
||||||
) {
|
) async {
|
||||||
return _mockRepository.saveExperience(staffId, industries, skills);
|
await _dataConnect
|
||||||
|
.updateStaff(id: staffId)
|
||||||
|
.industries(fdc.AnyValue(industries))
|
||||||
|
.skills(fdc.AnyValue(skills))
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
library staff_profile_experience;
|
library staff_profile_experience;
|
||||||
|
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter_modular/flutter_modular.dart';
|
import 'package:flutter_modular/flutter_modular.dart';
|
||||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||||
|
|
||||||
@@ -21,7 +22,10 @@ class StaffProfileExperienceModule extends Module {
|
|||||||
void binds(Injector i) {
|
void binds(Injector i) {
|
||||||
// Repository
|
// Repository
|
||||||
i.addLazySingleton<ExperienceRepositoryInterface>(
|
i.addLazySingleton<ExperienceRepositoryInterface>(
|
||||||
() => ExperienceRepositoryImpl(i.get<ProfileRepositoryMock>()),
|
() => ExperienceRepositoryImpl(
|
||||||
|
dataConnect: ExampleConnector.instance,
|
||||||
|
firebaseAuth: FirebaseAuth.instance,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// UseCases
|
// UseCases
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ dependencies:
|
|||||||
path: ../../../../../../core
|
path: ../../../../../../core
|
||||||
krow_data_connect:
|
krow_data_connect:
|
||||||
path: ../../../../../../data_connect
|
path: ../../../../../../data_connect
|
||||||
|
firebase_auth: ^5.0.0
|
||||||
design_system:
|
design_system:
|
||||||
path: ../../../../../../design_system
|
path: ../../../../../../design_system
|
||||||
core_localization:
|
core_localization:
|
||||||
|
|||||||
Reference in New Issue
Block a user