TF-2877 Create notification interactors and controller
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user