-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange_device_information_usecase.dart
67 lines (58 loc) · 2.4 KB
/
change_device_information_usecase.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright © 2022 Nevis Security AG. All rights reserved.
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/blocs/domain_state/domain_bloc.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/blocs/domain_state/domain_event.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/client_provider/client_provider.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/error/error_handler.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/model/operation/operation_type.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/repository/state_repository.dart';
abstract class ChangeDeviceInformationUseCase {
Future<void> execute({
String? name,
String? fcmRegistrationToken,
bool? disablePushNotifications,
});
}
@Injectable(as: ChangeDeviceInformationUseCase)
class ChangeDeviceInformationUseCaseImpl
implements ChangeDeviceInformationUseCase {
final ClientProvider _clientProvider;
final StateRepository<OperationType> _operationTypeRepository;
final DomainBloc _domainBloc;
final ErrorHandler _errorHandler;
ChangeDeviceInformationUseCaseImpl(
this._clientProvider,
this._operationTypeRepository,
this._domainBloc,
this._errorHandler,
);
@override
Future<void> execute({
String? name,
String? fcmRegistrationToken,
bool? disablePushNotifications,
}) async {
_operationTypeRepository.save(OperationType.deviceInformationChange);
var deviceInformationChange =
_clientProvider.client.operations.deviceInformationChange //
.onSuccess(() {
debugPrint('Change device information succeeded.');
_domainBloc.add(ResultEvent());
_operationTypeRepository.reset();
}).onError((error) {
debugPrint('Change device information failed: ${error.runtimeType}');
_errorHandler.handle(error);
});
if (name != null) {
deviceInformationChange.name(name);
}
if (fcmRegistrationToken != null) {
deviceInformationChange.fcmRegistrationToken(fcmRegistrationToken);
}
if (disablePushNotifications != null && disablePushNotifications) {
deviceInformationChange.disablePushNotifications();
}
return await deviceInformationChange.execute();
}
}