Files
unionflow-server-api/unionflow/unionflow-mobile-apps/lib/features/notifications/presentation/bloc/notification_bloc.dart
dahoud e8ad874015 feat: WebSocket temps réel + Finance Workflow + corrections
- Task #6: WebSocket /ws/dashboard + Kafka events (5 topics)
  * Backend: KafkaEventProducer, KafkaEventConsumer
  * Mobile: WebSocketService (reconnection, heartbeat, typed events)
  * DashboardBloc: Auto-refresh depuis WebSocket events

- Finance Workflow: approbations + budgets (backend + mobile)
  * Backend: entities, services, resources, migrations Flyway V6
  * Mobile: features finance_workflow complète avec BLoC

- Corrections DI: interfaces IRepository partout
  * IProfileRepository, IOrganizationRepository, IMembreRepository
  * GetIt configuré avec @injectable

- Spec-Kit: constitution + templates mis à jour
  * .specify/memory/constitution.md enrichie
  * Templates agent, plan, spec, tasks, checklist

- Nettoyage: fichiers temporaires supprimés

Signed-off-by: lions dev Team
2026-03-15 02:12:17 +00:00

55 lines
2.0 KiB
Dart

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import '../../../../core/utils/logger.dart';
import '../../data/repositories/notification_feed_repository.dart';
import 'notification_event.dart';
import 'notification_state.dart';
@injectable
class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
final NotificationFeedRepository _repository;
NotificationBloc(this._repository) : super(NotificationInitial()) {
on<LoadNotificationsRequested>(_onLoadNotificationsRequested);
on<NotificationMarkedAsRead>(_onNotificationMarkedAsRead);
}
Future<void> _onLoadNotificationsRequested(LoadNotificationsRequested event, Emitter<NotificationState> emit) async {
emit(NotificationLoading());
try {
final items = await _repository.getNotifications();
emit(NotificationLoaded(items: items));
} catch (e, st) {
AppLogger.error('NotificationBloc: chargement notifications échoué', error: e, stackTrace: st);
emit(NotificationError('Erreur de chargement: $e'));
}
}
Future<void> _onNotificationMarkedAsRead(NotificationMarkedAsRead event, Emitter<NotificationState> emit) async {
if (state is NotificationLoaded) {
final currentState = state as NotificationLoaded;
try {
await _repository.markAsRead(event.id);
final updatedItems = currentState.items.map((item) {
if (item.id == event.id) {
return NotificationItem(
id: item.id,
title: item.title,
body: item.body,
date: item.date,
isRead: true,
category: item.category,
);
}
return item;
}).toList();
emit(NotificationLoaded(items: updatedItems));
} catch (e, st) {
AppLogger.error('NotificationBloc: marquer comme lu échoué', error: e, stackTrace: st);
emit(NotificationError('Impossible de marquer comme lu'));
}
}
}
}