Refactor Staff and Store models to use fromMap method; enhance StoreCubit with provider management functionality
This commit is contained in:
@@ -54,6 +54,58 @@ class StoreCubit extends Cubit<StoreState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignProviderToStore(String storeId, String providerId) async {
|
||||
try {
|
||||
await _repository.associateProviderToStore(
|
||||
providerId: providerId,
|
||||
storeId: storeId,
|
||||
);
|
||||
// Dopo l'associazione, potresti voler ricaricare i provider per quel negozio
|
||||
final updatedProviders = await _repository.fetchProvidersForStore(
|
||||
storeId,
|
||||
);
|
||||
final newMap = Map<String, List<ProviderModel>>.from(
|
||||
state.providersByStore,
|
||||
);
|
||||
newMap[storeId] = updatedProviders;
|
||||
emit(state.copyWith(providersByStore: newMap));
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: StoreStatus.failure,
|
||||
errorMessage: "Errore nell'associazione: $e",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeProviderFromStore(
|
||||
String storeId,
|
||||
String providerId,
|
||||
) async {
|
||||
try {
|
||||
await _repository.removeProviderFromStore(
|
||||
providerId: providerId,
|
||||
storeId: storeId,
|
||||
);
|
||||
final updatedProviders = await _repository.fetchProvidersForStore(
|
||||
storeId,
|
||||
);
|
||||
final newMap = Map<String, List<ProviderModel>>.from(
|
||||
state.providersByStore,
|
||||
);
|
||||
newMap[storeId] = updatedProviders;
|
||||
emit(state.copyWith(providersByStore: newMap));
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: StoreStatus.failure,
|
||||
errorMessage: "Errore nella rimozione: $e",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignStaffToStore(String storeId, String staffId) async {
|
||||
try {
|
||||
await _staffRepository.assignToStore(staffId, storeId);
|
||||
|
||||
Reference in New Issue
Block a user