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:
@@ -0,0 +1,108 @@
|
||||
library analytics_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// Modèle pour une métrique analytics — aligné avec AnalyticsDataDTO
|
||||
class AnalyticsModel extends Equatable {
|
||||
final String? id;
|
||||
final String typeMetrique;
|
||||
final String periodeAnalyse;
|
||||
final double valeur;
|
||||
final double? valeurPrecedente;
|
||||
final double? pourcentageEvolution;
|
||||
final DateTime? dateDebut;
|
||||
final DateTime? dateFin;
|
||||
final String? libelle;
|
||||
final String? description;
|
||||
final String? unite;
|
||||
final String? couleur;
|
||||
final String? icone;
|
||||
|
||||
const AnalyticsModel({
|
||||
this.id,
|
||||
required this.typeMetrique,
|
||||
required this.periodeAnalyse,
|
||||
required this.valeur,
|
||||
this.valeurPrecedente,
|
||||
this.pourcentageEvolution,
|
||||
this.dateDebut,
|
||||
this.dateFin,
|
||||
this.libelle,
|
||||
this.description,
|
||||
this.unite,
|
||||
this.couleur,
|
||||
this.icone,
|
||||
});
|
||||
|
||||
bool get hasPositiveTrend =>
|
||||
pourcentageEvolution != null && pourcentageEvolution! > 0;
|
||||
bool get hasNegativeTrend =>
|
||||
pourcentageEvolution != null && pourcentageEvolution! < 0;
|
||||
|
||||
factory AnalyticsModel.fromJson(Map<String, dynamic> json) {
|
||||
return AnalyticsModel(
|
||||
id: json['id']?.toString(),
|
||||
typeMetrique: json['typeMetrique']?.toString() ?? '',
|
||||
periodeAnalyse: json['periodeAnalyse']?.toString() ?? '',
|
||||
valeur: _parseDouble(json['valeur']),
|
||||
valeurPrecedente: json['valeurPrecedente'] != null
|
||||
? _parseDouble(json['valeurPrecedente'])
|
||||
: null,
|
||||
pourcentageEvolution: json['pourcentageEvolution'] != null
|
||||
? _parseDouble(json['pourcentageEvolution'])
|
||||
: null,
|
||||
dateDebut: json['dateDebut'] != null
|
||||
? DateTime.tryParse(json['dateDebut'].toString())
|
||||
: null,
|
||||
dateFin: json['dateFin'] != null
|
||||
? DateTime.tryParse(json['dateFin'].toString())
|
||||
: null,
|
||||
libelle: json['libellePersonnalise']?.toString() ?? json['typeMetrique']?.toString(),
|
||||
description: json['description']?.toString(),
|
||||
unite: json['unite']?.toString(),
|
||||
couleur: json['couleur']?.toString(),
|
||||
icone: json['icone']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
static double _parseDouble(dynamic val) {
|
||||
if (val == null) return 0.0;
|
||||
if (val is num) return val.toDouble();
|
||||
return double.tryParse(val.toString()) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, typeMetrique, valeur, periodeAnalyse];
|
||||
}
|
||||
|
||||
/// KPI synthétique pour le tableau de bord des rapports
|
||||
class KpiModel extends Equatable {
|
||||
final String libelle;
|
||||
final double valeur;
|
||||
final String? unite;
|
||||
final double? evolution;
|
||||
final String? couleur;
|
||||
|
||||
const KpiModel({
|
||||
required this.libelle,
|
||||
required this.valeur,
|
||||
this.unite,
|
||||
this.evolution,
|
||||
this.couleur,
|
||||
});
|
||||
|
||||
factory KpiModel.fromJson(Map<String, dynamic> json) {
|
||||
return KpiModel(
|
||||
libelle: json['libelle']?.toString() ?? json['nom']?.toString() ?? '',
|
||||
valeur: AnalyticsModel._parseDouble(json['valeur'] ?? json['value']),
|
||||
unite: json['unite']?.toString(),
|
||||
evolution: json['evolution'] != null
|
||||
? AnalyticsModel._parseDouble(json['evolution'])
|
||||
: null,
|
||||
couleur: json['couleur']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [libelle, valeur];
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
library reports_repository;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import '../models/analytics_model.dart';
|
||||
|
||||
/// Interface du repository des rapports
|
||||
abstract class ReportsRepository {
|
||||
Future<List<AnalyticsModel>> getMetriques(String typeMetrique, String periode);
|
||||
Future<Map<String, dynamic>> getPerformanceGlobale();
|
||||
Future<List<AnalyticsModel>> getEvolutions(String typeMetrique);
|
||||
Future<Map<String, dynamic>> getStatistiquesMembres();
|
||||
Future<Map<String, dynamic>> getStatistiquesCotisations(int annee);
|
||||
Future<Map<String, dynamic>> getStatistiquesEvenements();
|
||||
}
|
||||
|
||||
/// Implémentation via /api/v1/analytics
|
||||
class ReportsRepositoryImpl implements ReportsRepository {
|
||||
final Dio _dio;
|
||||
static const String _analyticsBase = '/api/v1/analytics';
|
||||
static const String _membresBase = '/api/membres';
|
||||
static const String _cotisationsBase = '/api/cotisations';
|
||||
static const String _evenementsBase = '/api/evenements';
|
||||
|
||||
ReportsRepositoryImpl(this._dio);
|
||||
|
||||
@override
|
||||
Future<List<AnalyticsModel>> getMetriques(String typeMetrique, String periode) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'$_analyticsBase/metriques/$typeMetrique',
|
||||
queryParameters: {'periodeAnalyse': periode},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data is List) {
|
||||
return data.map((e) => AnalyticsModel.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
if (data is Map) {
|
||||
return [AnalyticsModel.fromJson(data as Map<String, dynamic>)];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404 || e.response?.statusCode == 400) return [];
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getPerformanceGlobale() async {
|
||||
try {
|
||||
final response = await _dio.get('$_analyticsBase/performance-globale');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<AnalyticsModel>> getEvolutions(String typeMetrique) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'$_analyticsBase/evolutions',
|
||||
queryParameters: {'typeMetrique': typeMetrique},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data is List) {
|
||||
return data.map((e) => AnalyticsModel.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
}
|
||||
return [];
|
||||
} on DioException {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getStatistiquesMembres() async {
|
||||
try {
|
||||
final response = await _dio.get('$_membresBase/statistiques');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getStatistiquesCotisations(int annee) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'$_cotisationsBase/statistiques',
|
||||
queryParameters: {'annee': annee},
|
||||
);
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getStatistiquesEvenements() async {
|
||||
try {
|
||||
final response = await _dio.get('$_evenementsBase/statistiques');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user