Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
@@ -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];
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import '../../presentation/bloc/notification_state.dart';
|
||||
|
||||
/// Repository pour l'onglet Notifications (flux DRY).
|
||||
/// Utilise ApiClient et mappe vers NotificationItem.
|
||||
@lazySingleton
|
||||
class NotificationFeedRepository {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
NotificationFeedRepository(this._apiClient);
|
||||
|
||||
/// Récupère le membre connecté (GET /api/membres/me) pour obtenir l'id.
|
||||
Future<String> _getMembreId() async {
|
||||
final response = await _apiClient.get('/api/membres/me');
|
||||
final id = response.data['id']?.toString();
|
||||
if (id == null || id.isEmpty) {
|
||||
throw Exception('Membre connecté introuvable');
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/// Liste des notifications du membre connecté (GET /api/notifications/membre/{membreId}).
|
||||
Future<List<NotificationItem>> getNotifications() async {
|
||||
try {
|
||||
final membreId = await _getMembreId();
|
||||
final response = await _apiClient.get('/api/notifications/membre/$membreId');
|
||||
final List<dynamic> data = response.data is List ? response.data as List : [];
|
||||
return data
|
||||
.map((json) => _itemFromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) return [];
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Marque une notification comme lue (POST /api/notifications/{id}/marquer-lue).
|
||||
Future<void> markAsRead(String id) async {
|
||||
await _apiClient.post('/api/notifications/$id/marquer-lue');
|
||||
}
|
||||
|
||||
static NotificationItem _itemFromJson(Map<String, dynamic> json) {
|
||||
final id = json['id']?.toString() ?? '';
|
||||
final sujet = json['sujet']?.toString() ?? 'Notification';
|
||||
final corps = json['corps']?.toString() ?? '';
|
||||
final dateEnvoi = json['dateEnvoi']?.toString();
|
||||
final dateLecture = json['dateLecture']?.toString();
|
||||
final date = dateEnvoi != null
|
||||
? DateTime.tryParse(dateEnvoi) ?? DateTime.now()
|
||||
: DateTime.now();
|
||||
final isRead = dateLecture != null || json['statut']?.toString() == 'LUE';
|
||||
final type = (json['typeNotification']?.toString() ?? 'SYSTEME').toLowerCase();
|
||||
final category = type.contains('cotisation') || type.contains('finance')
|
||||
? 'finance'
|
||||
: type.contains('event') || type.contains('evenement')
|
||||
? 'event'
|
||||
: 'system';
|
||||
return NotificationItem(
|
||||
id: id,
|
||||
title: sujet,
|
||||
body: corps,
|
||||
date: date,
|
||||
isRead: isRead,
|
||||
category: category,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
library notification_repository;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../../core/network/api_client.dart';
|
||||
import '../models/notification_model.dart';
|
||||
|
||||
/// Interface du repository des notifications
|
||||
abstract class NotificationRepository {
|
||||
/// Notifications du membre connecté (GET /api/notifications/me)
|
||||
Future<List<NotificationModel>> getMesNotifications();
|
||||
Future<List<NotificationModel>> getMesNonLues();
|
||||
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
|
||||
@LazySingleton(as: NotificationRepository)
|
||||
class NotificationRepositoryImpl implements NotificationRepository {
|
||||
final ApiClient _apiClient;
|
||||
static const String _baseUrl = '/api/notifications';
|
||||
|
||||
NotificationRepositoryImpl(this._apiClient);
|
||||
|
||||
@override
|
||||
Future<List<NotificationModel>> getMesNotifications() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/me');
|
||||
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>> getMesNonLues() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/me/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<List<NotificationModel>> getNotificationsByMembre(String membreId) async {
|
||||
try {
|
||||
final response = await _apiClient.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 _apiClient.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 _apiClient.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 _apiClient.post('$_baseUrl/$id/marquer-lue');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user