feat: Implement staff profile retrieval and sign-out use cases; refactor profile management in the client app
This commit is contained in:
@@ -25,4 +25,6 @@ export 'src/connectors/staff/domain/usecases/get_personal_info_completion_usecas
|
||||
export 'src/connectors/staff/domain/usecases/get_emergency_contacts_completion_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/get_experience_completion_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/get_tax_forms_completion_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/get_staff_profile_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/sign_out_staff_usecase.dart';
|
||||
export 'src/connectors/staff/data/repositories/staff_connector_repository_impl.dart';
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
/// Implementation of [StaffConnectorRepository].
|
||||
///
|
||||
@@ -137,4 +138,52 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
taxForms.isNotEmpty &&
|
||||
hasExperience;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Staff> getStaffProfile() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<GetStaffByIdData, GetStaffByIdVariables> response =
|
||||
await _service.connector
|
||||
.getStaffById(id: staffId)
|
||||
.execute();
|
||||
|
||||
if (response.data.staff == null) {
|
||||
throw const ServerException(
|
||||
technicalMessage: 'Staff not found',
|
||||
);
|
||||
}
|
||||
|
||||
final GetStaffByIdStaff rawStaff = response.data.staff!;
|
||||
|
||||
// Map the raw data connect object to the Domain Entity
|
||||
return Staff(
|
||||
id: rawStaff.id,
|
||||
authProviderId: rawStaff.userId,
|
||||
name: rawStaff.fullName,
|
||||
email: rawStaff.email ?? '',
|
||||
phone: rawStaff.phone,
|
||||
avatar: rawStaff.photoUrl,
|
||||
status: StaffStatus.active,
|
||||
address: rawStaff.addres,
|
||||
totalShifts: rawStaff.totalShifts,
|
||||
averageRating: rawStaff.averageRating,
|
||||
onTimeRate: rawStaff.onTimeRate,
|
||||
noShowCount: rawStaff.noShowCount,
|
||||
cancellationCount: rawStaff.cancellationCount,
|
||||
reliabilityScore: rawStaff.reliabilityScore,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> signOut() async {
|
||||
try {
|
||||
await _service.auth.signOut();
|
||||
_service.clearCache();
|
||||
} catch (e) {
|
||||
throw Exception('Error signing out: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
/// Repository interface for staff connector queries.
|
||||
///
|
||||
/// This interface defines the contract for accessing staff-related data
|
||||
@@ -30,4 +32,18 @@ abstract interface class StaffConnectorRepository {
|
||||
///
|
||||
/// Returns true if at least one tax form exists.
|
||||
Future<bool> getTaxFormsCompletion();
|
||||
|
||||
/// Fetches the full staff profile for the current authenticated user.
|
||||
///
|
||||
/// Returns a [Staff] entity containing all profile information.
|
||||
///
|
||||
/// Throws an exception if the profile cannot be retrieved.
|
||||
Future<Staff> getStaffProfile();
|
||||
|
||||
/// Signs out the current user.
|
||||
///
|
||||
/// Clears the user's session and authentication state.
|
||||
///
|
||||
/// Throws an exception if the sign-out fails.
|
||||
Future<void> signOut();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
import '../repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Use case for fetching a staff member's full profile information.
|
||||
///
|
||||
/// This use case encapsulates the business logic for retrieving the complete
|
||||
/// staff profile including personal info, ratings, and reliability scores.
|
||||
/// It delegates to the repository for data access.
|
||||
class GetStaffProfileUseCase extends UseCase<void, Staff> {
|
||||
/// Creates a [GetStaffProfileUseCase].
|
||||
///
|
||||
/// Requires a [StaffConnectorRepository] for data access.
|
||||
GetStaffProfileUseCase({
|
||||
required StaffConnectorRepository repository,
|
||||
}) : _repository = repository;
|
||||
|
||||
final StaffConnectorRepository _repository;
|
||||
|
||||
/// Executes the use case to get the staff profile.
|
||||
///
|
||||
/// Returns a [Staff] entity containing all profile information.
|
||||
///
|
||||
/// Throws an exception if the operation fails.
|
||||
@override
|
||||
Future<Staff> call([void params]) => _repository.getStaffProfile();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:krow_core/core.dart';
|
||||
|
||||
import '../repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Use case for signing out the current staff user.
|
||||
///
|
||||
/// This use case encapsulates the business logic for signing out,
|
||||
/// including clearing authentication state and cache.
|
||||
/// It delegates to the repository for data access.
|
||||
class SignOutStaffUseCase extends NoInputUseCase<void> {
|
||||
/// Creates a [SignOutStaffUseCase].
|
||||
///
|
||||
/// Requires a [StaffConnectorRepository] for data access.
|
||||
SignOutStaffUseCase({
|
||||
required StaffConnectorRepository repository,
|
||||
}) : _repository = repository;
|
||||
|
||||
final StaffConnectorRepository _repository;
|
||||
|
||||
/// Executes the use case to sign out the user.
|
||||
///
|
||||
/// Throws an exception if the operation fails.
|
||||
@override
|
||||
Future<void> call() => _repository.signOut();
|
||||
}
|
||||
Reference in New Issue
Block a user