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
This commit is contained in:
@@ -1,59 +1,20 @@
|
||||
/// Repository pour la gestion des organisations
|
||||
/// Interface avec l'API backend OrganizationResource
|
||||
library organization_repository;
|
||||
library organization_repository_impl;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import '../../domain/repositories/organization_repository.dart';
|
||||
import '../models/organization_model.dart';
|
||||
|
||||
/// Interface du repository des organisations
|
||||
abstract class OrganizationRepository {
|
||||
/// Récupère la liste des organisations avec pagination
|
||||
Future<List<OrganizationModel>> getOrganizations({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
String? recherche,
|
||||
});
|
||||
|
||||
/// Récupère une organisation par son ID
|
||||
Future<OrganizationModel?> getOrganizationById(String id);
|
||||
|
||||
/// Crée une nouvelle organisation
|
||||
Future<OrganizationModel> createOrganization(OrganizationModel organization);
|
||||
|
||||
/// Met à jour une organisation
|
||||
Future<OrganizationModel> updateOrganization(String id, OrganizationModel organization);
|
||||
|
||||
/// Supprime une organisation
|
||||
Future<void> deleteOrganization(String id);
|
||||
|
||||
/// Active une organisation
|
||||
Future<OrganizationModel> activateOrganization(String id);
|
||||
|
||||
/// Suspend une organisation
|
||||
Future<OrganizationModel> suspendOrganization(String id);
|
||||
|
||||
/// Recherche avancée d'organisations
|
||||
Future<List<OrganizationModel>> searchOrganizations({
|
||||
String? nom,
|
||||
TypeOrganization? type,
|
||||
StatutOrganization? statut,
|
||||
String? ville,
|
||||
String? region,
|
||||
String? pays,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
});
|
||||
|
||||
/// Récupère les statistiques des organisations
|
||||
Future<Map<String, dynamic>> getOrganizationsStats();
|
||||
}
|
||||
|
||||
/// Implémentation du repository des organisations
|
||||
class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
final Dio _dio;
|
||||
@LazySingleton(as: IOrganizationRepository)
|
||||
class OrganizationRepositoryImpl implements IOrganizationRepository {
|
||||
final ApiClient _apiClient;
|
||||
static const String _baseUrl = '/api/organisations';
|
||||
|
||||
OrganizationRepositoryImpl(this._dio);
|
||||
OrganizationRepositoryImpl(this._apiClient);
|
||||
|
||||
@override
|
||||
Future<List<OrganizationModel>> getOrganizations({
|
||||
@@ -71,12 +32,13 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
queryParams['recherche'] = recherche;
|
||||
}
|
||||
|
||||
final response = await _dio.get(
|
||||
final response = await _apiClient.get(
|
||||
_baseUrl,
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// Le backend retourne directement une liste [...]
|
||||
final List<dynamic> data = response.data as List<dynamic>;
|
||||
return data
|
||||
.map((json) => OrganizationModel.fromJson(json as Map<String, dynamic>))
|
||||
@@ -91,10 +53,29 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<OrganizationModel>> getMesOrganisations() async {
|
||||
try {
|
||||
const String path = '$_baseUrl/mes';
|
||||
final response = await _apiClient.get(path);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = response.data as List<dynamic>;
|
||||
return data
|
||||
.map((json) => OrganizationModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
throw Exception('Erreur lors de la récupération de mes organisations: ${response.statusCode}');
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération de mes organisations: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération de mes organisations: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<OrganizationModel?> getOrganizationById(String id) async {
|
||||
try {
|
||||
final response = await _dio.get('$_baseUrl/$id');
|
||||
final response = await _apiClient.get('$_baseUrl/$id');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return OrganizationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
@@ -116,7 +97,7 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
@override
|
||||
Future<OrganizationModel> createOrganization(OrganizationModel organization) async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
final response = await _apiClient.post(
|
||||
_baseUrl,
|
||||
data: organization.toJson(),
|
||||
);
|
||||
@@ -144,7 +125,7 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
@override
|
||||
Future<OrganizationModel> updateOrganization(String id, OrganizationModel organization) async {
|
||||
try {
|
||||
final response = await _dio.put(
|
||||
final response = await _apiClient.put(
|
||||
'$_baseUrl/$id',
|
||||
data: organization.toJson(),
|
||||
);
|
||||
@@ -172,7 +153,7 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
@override
|
||||
Future<void> deleteOrganization(String id) async {
|
||||
try {
|
||||
final response = await _dio.delete('$_baseUrl/$id');
|
||||
final response = await _apiClient.delete('$_baseUrl/$id');
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception('Erreur lors de la suppression de l\'organisation: ${response.statusCode}');
|
||||
@@ -195,7 +176,7 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
@override
|
||||
Future<OrganizationModel> activateOrganization(String id) async {
|
||||
try {
|
||||
final response = await _dio.post('$_baseUrl/$id/activer');
|
||||
final response = await _apiClient.post('$_baseUrl/$id/activer');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return OrganizationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
@@ -215,7 +196,7 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
@override
|
||||
Future<OrganizationModel> suspendOrganization(String id) async {
|
||||
try {
|
||||
final response = await _dio.post('$_baseUrl/$id/suspendre');
|
||||
final response = await _apiClient.post('$_baseUrl/$id/suspendre');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return OrganizationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
@@ -256,12 +237,13 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
if (region?.isNotEmpty == true) queryParams['region'] = region;
|
||||
if (pays?.isNotEmpty == true) queryParams['pays'] = pays;
|
||||
|
||||
final response = await _dio.get(
|
||||
final response = await _apiClient.get(
|
||||
'$_baseUrl/recherche',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// Le backend retourne directement une liste [...]
|
||||
final List<dynamic> data = response.data as List<dynamic>;
|
||||
return data
|
||||
.map((json) => OrganizationModel.fromJson(json as Map<String, dynamic>))
|
||||
@@ -276,10 +258,62 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getOrganizationMembers(String organizationId) async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/$organizationId/membres');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = response.data as List<dynamic>;
|
||||
return data.map((e) => Map<String, dynamic>.from(e as Map)).toList();
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des membres: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw Exception('Organisation non trouvée');
|
||||
}
|
||||
throw Exception('Erreur réseau lors de la récupération des membres: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des membres: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<OrganizationModel> updateOrganizationConfig(
|
||||
String id,
|
||||
Map<String, dynamic> config,
|
||||
) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'$_baseUrl/$id/configuration',
|
||||
data: config,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return OrganizationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la mise à jour de la configuration: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw Exception('Organisation non trouvée');
|
||||
} else if (e.response?.statusCode == 400) {
|
||||
final errorData = e.response?.data;
|
||||
if (errorData is Map<String, dynamic> && errorData.containsKey('error')) {
|
||||
throw Exception('Configuration invalide: ${errorData['error']}');
|
||||
}
|
||||
}
|
||||
throw Exception('Erreur réseau lors de la mise à jour de la configuration: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la mise à jour de la configuration: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getOrganizationsStats() async {
|
||||
try {
|
||||
final response = await _dio.get('$_baseUrl/statistiques');
|
||||
final response = await _apiClient.get('$_baseUrl/statistiques');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
@@ -292,5 +326,4 @@ class OrganizationRepositoryImpl implements OrganizationRepository {
|
||||
throw Exception('Erreur inattendue lors de la récupération des statistiques: $e');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user