TF-2877 Create notification interactors and controller

This commit is contained in:
DatDang
2024-06-04 10:04:14 +07:00
committed by Dat H. Pham
parent b89820618c
commit ef0e4ad2a8
10 changed files with 454 additions and 0 deletions
@@ -0,0 +1,22 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/manage_account/domain/repository/notification_repository.dart';
import 'package:tmail_ui_user/features/manage_account/domain/state/get_notification_setting_state.dart';
class GetNotificationSettingInteractor {
final NotificationRepository _notificationRepository;
GetNotificationSettingInteractor(this._notificationRepository);
Stream<Either<Failure, Success>> execute(UserName userName) async* {
try {
yield Right(GettingNotificationSetting());
final isEnabled = await _notificationRepository.getNotificationSetting(userName);
yield Right(GetNotificationSettingSuccess(isEnabled: isEnabled));
} catch (_) {
yield Left(GetNotificationSettingFailure());
}
}
}
@@ -0,0 +1,22 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/manage_account/domain/repository/notification_repository.dart';
import 'package:tmail_ui_user/features/manage_account/domain/state/toggle_notification_setting_state.dart';
class ToggleNotificationSettingInteractor {
final NotificationRepository _notificationRepository;
ToggleNotificationSettingInteractor(this._notificationRepository);
Stream<Either<Failure, Success>> execute() async* {
try {
yield Right(TogglingNotificationSetting());
await _notificationRepository.toggleNotificationSetting();
yield Right(ToggleNotificationSettingSuccess());
} catch (_) {
yield Left(ToggleNotificationSettingFailure());
}
}
}