389 lines
11 KiB
Dart
389 lines
11 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import '../../../../core/error/failures.dart';
|
|
import '../../../../core/usecases/usecase.dart';
|
|
import '../entities/notification.dart';
|
|
import '../repositories/notifications_repository.dart';
|
|
|
|
/// Use case pour marquer une notification comme lue
|
|
class MarquerCommeLueUseCase implements UseCase<void, MarquerCommeLueParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
MarquerCommeLueUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(MarquerCommeLueParams params) async {
|
|
return await repository.marquerCommeLue(
|
|
params.notificationId,
|
|
params.utilisateurId,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour marquer comme lue
|
|
class MarquerCommeLueParams {
|
|
final String notificationId;
|
|
final String utilisateurId;
|
|
|
|
const MarquerCommeLueParams({
|
|
required this.notificationId,
|
|
required this.utilisateurId,
|
|
});
|
|
|
|
@override
|
|
String toString() {
|
|
return 'MarquerCommeLueParams{notificationId: $notificationId, utilisateurId: $utilisateurId}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour marquer toutes les notifications comme lues
|
|
class MarquerToutesCommeLuesUseCase implements UseCase<void, String> {
|
|
final NotificationsRepository repository;
|
|
|
|
MarquerToutesCommeLuesUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(String utilisateurId) async {
|
|
return await repository.marquerToutesCommeLues(utilisateurId);
|
|
}
|
|
}
|
|
|
|
/// Use case pour marquer une notification comme importante
|
|
class MarquerCommeImportanteUseCase implements UseCase<void, MarquerCommeImportanteParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
MarquerCommeImportanteUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(MarquerCommeImportanteParams params) async {
|
|
return await repository.marquerCommeImportante(
|
|
params.notificationId,
|
|
params.utilisateurId,
|
|
params.importante,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour marquer comme importante
|
|
class MarquerCommeImportanteParams {
|
|
final String notificationId;
|
|
final String utilisateurId;
|
|
final bool importante;
|
|
|
|
const MarquerCommeImportanteParams({
|
|
required this.notificationId,
|
|
required this.utilisateurId,
|
|
required this.importante,
|
|
});
|
|
|
|
@override
|
|
String toString() {
|
|
return 'MarquerCommeImportanteParams{notificationId: $notificationId, utilisateurId: $utilisateurId, importante: $importante}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour archiver une notification
|
|
class ArchiverNotificationUseCase implements UseCase<void, ArchiverNotificationParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
ArchiverNotificationUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(ArchiverNotificationParams params) async {
|
|
return await repository.archiverNotification(
|
|
params.notificationId,
|
|
params.utilisateurId,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour archiver une notification
|
|
class ArchiverNotificationParams {
|
|
final String notificationId;
|
|
final String utilisateurId;
|
|
|
|
const ArchiverNotificationParams({
|
|
required this.notificationId,
|
|
required this.utilisateurId,
|
|
});
|
|
|
|
@override
|
|
String toString() {
|
|
return 'ArchiverNotificationParams{notificationId: $notificationId, utilisateurId: $utilisateurId}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour archiver toutes les notifications lues
|
|
class ArchiverToutesLuesUseCase implements UseCase<void, String> {
|
|
final NotificationsRepository repository;
|
|
|
|
ArchiverToutesLuesUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(String utilisateurId) async {
|
|
return await repository.archiverToutesLues(utilisateurId);
|
|
}
|
|
}
|
|
|
|
/// Use case pour supprimer une notification
|
|
class SupprimerNotificationUseCase implements UseCase<void, SupprimerNotificationParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
SupprimerNotificationUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(SupprimerNotificationParams params) async {
|
|
return await repository.supprimerNotification(
|
|
params.notificationId,
|
|
params.utilisateurId,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour supprimer une notification
|
|
class SupprimerNotificationParams {
|
|
final String notificationId;
|
|
final String utilisateurId;
|
|
|
|
const SupprimerNotificationParams({
|
|
required this.notificationId,
|
|
required this.utilisateurId,
|
|
});
|
|
|
|
@override
|
|
String toString() {
|
|
return 'SupprimerNotificationParams{notificationId: $notificationId, utilisateurId: $utilisateurId}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour supprimer toutes les notifications archivées
|
|
class SupprimerToutesArchiveesUseCase implements UseCase<void, String> {
|
|
final NotificationsRepository repository;
|
|
|
|
SupprimerToutesArchiveesUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(String utilisateurId) async {
|
|
return await repository.supprimerToutesArchivees(utilisateurId);
|
|
}
|
|
}
|
|
|
|
/// Use case pour exécuter une action rapide
|
|
class ExecuterActionRapideUseCase implements UseCase<Map<String, dynamic>, ExecuterActionRapideParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
ExecuterActionRapideUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, Map<String, dynamic>>> call(ExecuterActionRapideParams params) async {
|
|
return await repository.executerActionRapide(
|
|
params.notificationId,
|
|
params.actionId,
|
|
params.utilisateurId,
|
|
parametres: params.parametres,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour exécuter une action rapide
|
|
class ExecuterActionRapideParams {
|
|
final String notificationId;
|
|
final String actionId;
|
|
final String utilisateurId;
|
|
final Map<String, dynamic>? parametres;
|
|
|
|
const ExecuterActionRapideParams({
|
|
required this.notificationId,
|
|
required this.actionId,
|
|
required this.utilisateurId,
|
|
this.parametres,
|
|
});
|
|
|
|
ExecuterActionRapideParams copyWith({
|
|
String? notificationId,
|
|
String? actionId,
|
|
String? utilisateurId,
|
|
Map<String, dynamic>? parametres,
|
|
}) {
|
|
return ExecuterActionRapideParams(
|
|
notificationId: notificationId ?? this.notificationId,
|
|
actionId: actionId ?? this.actionId,
|
|
utilisateurId: utilisateurId ?? this.utilisateurId,
|
|
parametres: parametres ?? this.parametres,
|
|
);
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'ExecuterActionRapideParams{notificationId: $notificationId, actionId: $actionId, utilisateurId: $utilisateurId, parametres: $parametres}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour signaler une notification comme spam
|
|
class SignalerSpamUseCase implements UseCase<void, SignalerSpamParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
SignalerSpamUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(SignalerSpamParams params) async {
|
|
return await repository.signalerSpam(
|
|
params.notificationId,
|
|
params.utilisateurId,
|
|
params.raison,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour signaler comme spam
|
|
class SignalerSpamParams {
|
|
final String notificationId;
|
|
final String utilisateurId;
|
|
final String raison;
|
|
|
|
const SignalerSpamParams({
|
|
required this.notificationId,
|
|
required this.utilisateurId,
|
|
required this.raison,
|
|
});
|
|
|
|
@override
|
|
String toString() {
|
|
return 'SignalerSpamParams{notificationId: $notificationId, utilisateurId: $utilisateurId, raison: $raison}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour synchroniser les notifications
|
|
class SynchroniserNotificationsUseCase implements UseCase<void, SynchroniserNotificationsParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
SynchroniserNotificationsUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(SynchroniserNotificationsParams params) async {
|
|
return await repository.synchroniser(
|
|
params.utilisateurId,
|
|
forceSync: params.forceSync,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour synchroniser les notifications
|
|
class SynchroniserNotificationsParams {
|
|
final String utilisateurId;
|
|
final bool forceSync;
|
|
|
|
const SynchroniserNotificationsParams({
|
|
required this.utilisateurId,
|
|
this.forceSync = false,
|
|
});
|
|
|
|
SynchroniserNotificationsParams copyWith({
|
|
String? utilisateurId,
|
|
bool? forceSync,
|
|
}) {
|
|
return SynchroniserNotificationsParams(
|
|
utilisateurId: utilisateurId ?? this.utilisateurId,
|
|
forceSync: forceSync ?? this.forceSync,
|
|
);
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'SynchroniserNotificationsParams{utilisateurId: $utilisateurId, forceSync: $forceSync}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour vider le cache des notifications
|
|
class ViderCacheNotificationsUseCase implements UseCase<void, String?> {
|
|
final NotificationsRepository repository;
|
|
|
|
ViderCacheNotificationsUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, void>> call(String? utilisateurId) async {
|
|
return await repository.viderCache(utilisateurId);
|
|
}
|
|
}
|
|
|
|
/// Use case pour envoyer une notification de test
|
|
class EnvoyerNotificationTestUseCase implements UseCase<NotificationEntity, EnvoyerNotificationTestParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
EnvoyerNotificationTestUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, NotificationEntity>> call(EnvoyerNotificationTestParams params) async {
|
|
return await repository.envoyerNotificationTest(
|
|
params.utilisateurId,
|
|
params.type,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour envoyer une notification de test
|
|
class EnvoyerNotificationTestParams {
|
|
final String utilisateurId;
|
|
final TypeNotification type;
|
|
|
|
const EnvoyerNotificationTestParams({
|
|
required this.utilisateurId,
|
|
required this.type,
|
|
});
|
|
|
|
@override
|
|
String toString() {
|
|
return 'EnvoyerNotificationTestParams{utilisateurId: $utilisateurId, type: $type}';
|
|
}
|
|
}
|
|
|
|
/// Use case pour exporter les notifications
|
|
class ExporterNotificationsUseCase implements UseCase<String, ExporterNotificationsParams> {
|
|
final NotificationsRepository repository;
|
|
|
|
ExporterNotificationsUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, String>> call(ExporterNotificationsParams params) async {
|
|
return await repository.exporterNotifications(
|
|
params.utilisateurId,
|
|
params.format,
|
|
dateDebut: params.dateDebut,
|
|
dateFin: params.dateFin,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Paramètres pour exporter les notifications
|
|
class ExporterNotificationsParams {
|
|
final String utilisateurId;
|
|
final String format;
|
|
final DateTime? dateDebut;
|
|
final DateTime? dateFin;
|
|
|
|
const ExporterNotificationsParams({
|
|
required this.utilisateurId,
|
|
required this.format,
|
|
this.dateDebut,
|
|
this.dateFin,
|
|
});
|
|
|
|
ExporterNotificationsParams copyWith({
|
|
String? utilisateurId,
|
|
String? format,
|
|
DateTime? dateDebut,
|
|
DateTime? dateFin,
|
|
}) {
|
|
return ExporterNotificationsParams(
|
|
utilisateurId: utilisateurId ?? this.utilisateurId,
|
|
format: format ?? this.format,
|
|
dateDebut: dateDebut ?? this.dateDebut,
|
|
dateFin: dateFin ?? this.dateFin,
|
|
);
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'ExporterNotificationsParams{utilisateurId: $utilisateurId, format: $format, dateDebut: $dateDebut, dateFin: $dateFin}';
|
|
}
|
|
}
|