feat(unionflow): ajout Spec-Kit, constitution, mission mutuelles

- Config Spec-Kit pour Spec-Driven Development
- CONSTITUTION.md + .specify/memory/constitution.md
- Commandes Cursor /speckit.*, règles projet
- Mission: associations + mutuelles d'épargne et de financement
- .gitignore: versionner config spec-kit unionflow

Made-with: Cursor
This commit is contained in:
dahoud
2026-02-27 14:41:07 +00:00
parent 144b68f8e7
commit b1957c1c81
631 changed files with 104070 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
library notification_model;
import 'package:equatable/equatable.dart';
/// Modèle de données pour une notification
/// Aligné avec NotificationDTO côté backend
class NotificationModel extends Equatable {
final String id;
final String typeNotification;
final String? priorite;
final String? statut;
final String? sujet;
final String? corps;
final DateTime? dateEnvoiPrevue;
final DateTime? dateEnvoi;
final DateTime? dateLecture;
final String? donneesAdditionnelles;
final String? membreId;
final String? organisationId;
const NotificationModel({
required this.id,
required this.typeNotification,
this.priorite,
this.statut,
this.sujet,
this.corps,
this.dateEnvoiPrevue,
this.dateEnvoi,
this.dateLecture,
this.donneesAdditionnelles,
this.membreId,
this.organisationId,
});
bool get estLue => statut == 'LUE' || dateLecture != null;
String get typeAffichage {
switch (typeNotification) {
case 'EVENEMENT':
return 'Événements';
case 'MEMBRE':
return 'Membres';
case 'ORGANISATION':
return 'Organisations';
case 'COTISATION':
return 'Cotisations';
case 'ADHESION':
return 'Adhésions';
default:
return 'Système';
}
}
factory NotificationModel.fromJson(Map<String, dynamic> json) {
return NotificationModel(
id: json['id']?.toString() ?? '',
typeNotification: json['typeNotification']?.toString() ?? 'SYSTEME',
priorite: json['priorite']?.toString(),
statut: json['statut']?.toString(),
sujet: json['sujet']?.toString(),
corps: json['corps']?.toString(),
dateEnvoiPrevue: json['dateEnvoiPrevue'] != null
? DateTime.tryParse(json['dateEnvoiPrevue'].toString())
: null,
dateEnvoi: json['dateEnvoi'] != null
? DateTime.tryParse(json['dateEnvoi'].toString())
: null,
dateLecture: json['dateLecture'] != null
? DateTime.tryParse(json['dateLecture'].toString())
: null,
donneesAdditionnelles: json['donneesAdditionnelles']?.toString(),
membreId: json['membreId']?.toString(),
organisationId: json['organisationId']?.toString(),
);
}
Map<String, dynamic> toJson() => {
'id': id,
'typeNotification': typeNotification,
'priorite': priorite,
'statut': statut,
'sujet': sujet,
'corps': corps,
'dateEnvoiPrevue': dateEnvoiPrevue?.toIso8601String(),
'dateEnvoi': dateEnvoi?.toIso8601String(),
'dateLecture': dateLecture?.toIso8601String(),
'donneesAdditionnelles': donneesAdditionnelles,
'membreId': membreId,
'organisationId': organisationId,
};
@override
List<Object?> get props => [id, typeNotification, statut, dateLecture];
}

View File

@@ -0,0 +1,75 @@
library notification_repository;
import 'package:dio/dio.dart';
import '../models/notification_model.dart';
/// Interface du repository des notifications
abstract class NotificationRepository {
Future<List<NotificationModel>> getNotificationsByMembre(String membreId);
Future<List<NotificationModel>> getNonLuesByMembre(String membreId);
Future<NotificationModel?> getNotificationById(String id);
Future<void> marquerCommeLue(String id);
}
/// Implémentation via /api/notifications
class NotificationRepositoryImpl implements NotificationRepository {
final Dio _dio;
static const String _baseUrl = '/api/notifications';
NotificationRepositoryImpl(this._dio);
@override
Future<List<NotificationModel>> getNotificationsByMembre(String membreId) async {
try {
final response = await _dio.get('$_baseUrl/membre/$membreId');
if (response.statusCode == 200) {
final data = response.data;
final list = data is List ? data : (data['content'] as List? ?? []);
return list
.map((e) => NotificationModel.fromJson(e as Map<String, dynamic>))
.toList();
}
return [];
} on DioException catch (e) {
if (e.response?.statusCode == 404) return [];
rethrow;
}
}
@override
Future<List<NotificationModel>> getNonLuesByMembre(String membreId) async {
try {
final response = await _dio.get('$_baseUrl/membre/$membreId/non-lues');
if (response.statusCode == 200) {
final data = response.data;
final list = data is List ? data : (data['content'] as List? ?? []);
return list
.map((e) => NotificationModel.fromJson(e as Map<String, dynamic>))
.toList();
}
return [];
} on DioException catch (e) {
if (e.response?.statusCode == 404) return [];
rethrow;
}
}
@override
Future<NotificationModel?> getNotificationById(String id) async {
try {
final response = await _dio.get('$_baseUrl/$id');
if (response.statusCode == 200) {
return NotificationModel.fromJson(response.data as Map<String, dynamic>);
}
return null;
} on DioException catch (e) {
if (e.response?.statusCode == 404) return null;
rethrow;
}
}
@override
Future<void> marquerCommeLue(String id) async {
await _dio.post('$_baseUrl/$id/marquer-lue');
}
}

View File

@@ -0,0 +1,25 @@
library notifications_di;
import 'package:get_it/get_it.dart';
import 'package:dio/dio.dart';
import '../data/repositories/notification_repository.dart';
import '../presentation/bloc/notifications_bloc.dart';
class NotificationsDI {
static final GetIt _getIt = GetIt.instance;
static void register() {
_getIt.registerLazySingleton<NotificationRepository>(
() => NotificationRepositoryImpl(_getIt<Dio>()),
);
_getIt.registerFactory<NotificationsBloc>(
() => NotificationsBloc(_getIt<NotificationRepository>()),
);
}
static void unregister() {
if (_getIt.isRegistered<NotificationsBloc>()) _getIt.unregister<NotificationsBloc>();
if (_getIt.isRegistered<NotificationRepository>()) _getIt.unregister<NotificationRepository>();
}
}

View File

@@ -0,0 +1,86 @@
library notifications_bloc;
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:dio/dio.dart';
import '../../data/models/notification_model.dart';
import '../../data/repositories/notification_repository.dart';
part 'notifications_event.dart';
part 'notifications_state.dart';
class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
final NotificationRepository _repository;
NotificationsBloc(this._repository) : super(const NotificationsInitial()) {
on<LoadNotifications>(_onLoadNotifications);
on<MarkNotificationAsRead>(_onMarkAsRead);
on<RefreshNotifications>(_onRefresh);
}
Future<void> _onLoadNotifications(
LoadNotifications event,
Emitter<NotificationsState> emit,
) async {
try {
emit(const NotificationsLoading());
final notifications = await _repository.getNotificationsByMembre(event.membreId);
final nonLues = notifications.where((n) => !n.estLue).length;
emit(NotificationsLoaded(notifications: notifications, nonLuesCount: nonLues));
} on DioException catch (e) {
emit(NotificationsError(_networkError(e)));
} catch (e) {
emit(NotificationsError('Erreur lors du chargement : $e'));
}
}
Future<void> _onMarkAsRead(
MarkNotificationAsRead event,
Emitter<NotificationsState> emit,
) async {
try {
await _repository.marquerCommeLue(event.notificationId);
final currentState = state;
if (currentState is NotificationsLoaded) {
final updated = currentState.notifications.map((n) {
if (n.id == event.notificationId) {
return NotificationModel(
id: n.id,
typeNotification: n.typeNotification,
priorite: n.priorite,
statut: 'LUE',
sujet: n.sujet,
corps: n.corps,
dateEnvoiPrevue: n.dateEnvoiPrevue,
dateEnvoi: n.dateEnvoi,
dateLecture: DateTime.now(),
donneesAdditionnelles: n.donneesAdditionnelles,
membreId: n.membreId,
organisationId: n.organisationId,
);
}
return n;
}).toList();
final nonLues = updated.where((n) => !n.estLue).length;
emit(NotificationMarkedAsRead(notifications: updated, nonLuesCount: nonLues));
}
} catch (e) {
// Echec silencieux : ne pas bloquer l'UI
}
}
Future<void> _onRefresh(
RefreshNotifications event,
Emitter<NotificationsState> emit,
) async {
add(LoadNotifications(membreId: event.membreId));
}
String _networkError(DioException e) {
final code = e.response?.statusCode;
if (code == 401) return 'Non autorisé.';
if (code == 403) return 'Accès refusé.';
if (code != null && code >= 500) return 'Erreur serveur.';
return 'Erreur réseau. Vérifiez votre connexion.';
}
}

View File

@@ -0,0 +1,33 @@
part of 'notifications_bloc.dart';
abstract class NotificationsEvent extends Equatable {
const NotificationsEvent();
@override
List<Object?> get props => [];
}
class LoadNotifications extends NotificationsEvent {
final String membreId;
final bool onlyUnread;
const LoadNotifications({required this.membreId, this.onlyUnread = false});
@override
List<Object?> get props => [membreId, onlyUnread];
}
class MarkNotificationAsRead extends NotificationsEvent {
final String notificationId;
const MarkNotificationAsRead(this.notificationId);
@override
List<Object?> get props => [notificationId];
}
class RefreshNotifications extends NotificationsEvent {
final String membreId;
const RefreshNotifications(this.membreId);
@override
List<Object?> get props => [membreId];
}

View File

@@ -0,0 +1,50 @@
part of 'notifications_bloc.dart';
abstract class NotificationsState extends Equatable {
const NotificationsState();
@override
List<Object?> get props => [];
}
class NotificationsInitial extends NotificationsState {
const NotificationsInitial();
}
class NotificationsLoading extends NotificationsState {
const NotificationsLoading();
}
class NotificationsLoaded extends NotificationsState {
final List<NotificationModel> notifications;
final int nonLuesCount;
const NotificationsLoaded({
required this.notifications,
required this.nonLuesCount,
});
@override
List<Object?> get props => [notifications, nonLuesCount];
}
class NotificationMarkedAsRead extends NotificationsState {
final List<NotificationModel> notifications;
final int nonLuesCount;
const NotificationMarkedAsRead({
required this.notifications,
required this.nonLuesCount,
});
@override
List<Object?> get props => [notifications, nonLuesCount];
}
class NotificationsError extends NotificationsState {
final String message;
const NotificationsError(this.message);
@override
List<Object?> get props => [message];
}

View File

@@ -0,0 +1,20 @@
library notifications_page_wrapper;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import '../bloc/notifications_bloc.dart';
import 'notifications_page.dart';
/// Wrapper qui fournit le NotificationsBloc à la NotificationsPage
class NotificationsPageWrapper extends StatelessWidget {
const NotificationsPageWrapper({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider<NotificationsBloc>(
create: (_) => GetIt.instance<NotificationsBloc>(),
child: const NotificationsPage(),
);
}
}