Skip to content

Commit 583aa97

Browse files
authored
Merge pull request #104 from flutter-news-app-full-source-code/refactor/sync-with-core-package-update
Refactor/sync with core package update
2 parents 009a245 + 0c96edc commit 583aa97

21 files changed

+429
-114
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ analyzer:
1111
document_ignores: ignore
1212
one_member_abstracts: ignore
1313
cascade_invocations: ignore
14+
cast_nullable_to_non_nullable: ignore
1415
exclude:
1516
- build/**
1617
linter:

lib/src/config/app_dependencies.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AppDependencies {
6565
late final DataRepository<Country> countryRepository;
6666
late final DataRepository<Language> languageRepository;
6767
late final DataRepository<User> userRepository;
68-
late final DataRepository<UserAppSettings> userAppSettingsRepository;
68+
late final DataRepository<AppSettings> appSettingsRepository;
6969
late final DataRepository<UserContentPreferences>
7070
userContentPreferencesRepository;
7171
late final DataRepository<PushNotificationDevice>
@@ -190,12 +190,12 @@ class AppDependencies {
190190
toJson: (item) => item.toJson(),
191191
logger: Logger('DataMongodb<User>'),
192192
);
193-
final userAppSettingsClient = DataMongodb<UserAppSettings>(
193+
final appSettingsClient = DataMongodb<AppSettings>(
194194
connectionManager: _mongoDbConnectionManager,
195-
modelName: 'user_app_settings',
196-
fromJson: UserAppSettings.fromJson,
195+
modelName: 'app_settings',
196+
fromJson: AppSettings.fromJson,
197197
toJson: (item) => item.toJson(),
198-
logger: Logger('DataMongodb<UserAppSettings>'),
198+
logger: Logger('DataMongodb<AppSettings>'),
199199
);
200200
final userContentPreferencesClient = DataMongodb<UserContentPreferences>(
201201
connectionManager: _mongoDbConnectionManager,
@@ -306,8 +306,8 @@ class AppDependencies {
306306
countryRepository = DataRepository(dataClient: countryClient);
307307
languageRepository = DataRepository(dataClient: languageClient);
308308
userRepository = DataRepository(dataClient: userClient);
309-
userAppSettingsRepository = DataRepository(
310-
dataClient: userAppSettingsClient,
309+
appSettingsRepository = DataRepository(
310+
dataClient: appSettingsClient,
311311
);
312312
userContentPreferencesRepository = DataRepository(
313313
dataClient: userContentPreferencesClient,
@@ -359,7 +359,7 @@ class AppDependencies {
359359
verificationCodeStorageService: verificationCodeStorageService,
360360
permissionService: permissionService,
361361
emailRepository: emailRepository,
362-
userAppSettingsRepository: userAppSettingsRepository,
362+
appSettingsRepository: appSettingsRepository,
363363
userContentPreferencesRepository: userContentPreferencesRepository,
364364
log: Logger('AuthService'),
365365
);

lib/src/models/models.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'push_notification/push_notification.dart';
2+
export 'request_id.dart';
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import 'package:core/core.dart';
2+
import 'package:equatable/equatable.dart';
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'firebase_request_body.g.dart';
6+
7+
/// {@template firebase_request_body}
8+
/// Represents the top-level structure for a Firebase Cloud Messaging
9+
/// v1 API request.
10+
/// {@endtemplate}
11+
@JsonSerializable(
12+
explicitToJson: true,
13+
includeIfNull: true,
14+
checked: true,
15+
createFactory: false,
16+
)
17+
class FirebaseRequestBody extends Equatable {
18+
/// {@macro firebase_request_body}
19+
const FirebaseRequestBody({required this.message});
20+
21+
/// The message payload.
22+
final FirebaseMessage message;
23+
24+
/// Converts this [FirebaseRequestBody] instance to a JSON map.
25+
Map<String, dynamic> toJson() => _$FirebaseRequestBodyToJson(this);
26+
27+
@override
28+
List<Object> get props => [message];
29+
}
30+
31+
/// {@template firebase_message}
32+
/// Represents the message object within a Firebase request.
33+
/// {@endtemplate}
34+
@JsonSerializable(
35+
explicitToJson: true,
36+
includeIfNull: true,
37+
checked: true,
38+
createFactory: false,
39+
)
40+
class FirebaseMessage extends Equatable {
41+
/// {@macro firebase_message}
42+
const FirebaseMessage({
43+
required this.token,
44+
required this.notification,
45+
required this.data,
46+
});
47+
48+
/// The registration token of the device to send the message to.
49+
final String token;
50+
51+
/// The notification content.
52+
final FirebaseNotification notification;
53+
54+
/// The custom data payload.
55+
final PushNotificationPayload data;
56+
57+
/// Converts this [FirebaseMessage] instance to a JSON map.
58+
Map<String, dynamic> toJson() => _$FirebaseMessageToJson(this);
59+
60+
@override
61+
List<Object> get props => [token, notification, data];
62+
}
63+
64+
/// {@template firebase_notification}
65+
/// Represents the notification content within a Firebase message.
66+
/// {@endtemplate}
67+
@JsonSerializable(
68+
explicitToJson: true,
69+
includeIfNull: true,
70+
checked: true,
71+
createFactory: false,
72+
)
73+
class FirebaseNotification extends Equatable {
74+
/// {@macro firebase_notification}
75+
const FirebaseNotification({
76+
required this.title,
77+
this.body,
78+
this.image,
79+
});
80+
81+
/// The notification's title.
82+
final String title;
83+
84+
/// The notification's body text.
85+
final String? body;
86+
87+
/// The URL of an image to be displayed in the notification.
88+
final String? image;
89+
90+
/// Converts this [FirebaseNotification] instance to a JSON map.
91+
Map<String, dynamic> toJson() => _$FirebaseNotificationToJson(this);
92+
93+
@override
94+
List<Object?> get props => [title, body, image];
95+
}

lib/src/models/push_notification/firebase_request_body.g.dart

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import 'package:core/core.dart';
2+
import 'package:equatable/equatable.dart';
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'onesignal_request_body.g.dart';
6+
7+
/// {@template onesignal_request_body}
8+
/// Represents the request body for the OneSignal /notifications endpoint.
9+
/// {@endtemplate}
10+
@JsonSerializable(
11+
explicitToJson: true,
12+
includeIfNull: false, // Do not include null fields in the JSON
13+
checked: true,
14+
fieldRename: FieldRename.snake,
15+
createFactory: false,
16+
)
17+
class OneSignalRequestBody extends Equatable {
18+
/// {@macro onesignal_request_body}
19+
const OneSignalRequestBody({
20+
required this.appId,
21+
required this.includePlayerIds,
22+
required this.headings,
23+
required this.data,
24+
this.contents,
25+
this.bigPicture,
26+
});
27+
28+
/// The OneSignal App ID.
29+
final String appId;
30+
31+
/// A list of OneSignal Player IDs to send the notification to.
32+
final List<String> includePlayerIds;
33+
34+
/// The notification's title.
35+
final Map<String, String> headings;
36+
37+
/// The notification's content.
38+
final Map<String, String>? contents;
39+
40+
/// The custom data payload
41+
final PushNotificationPayload data;
42+
43+
/// The URL of a large image to display in the notification.
44+
final String? bigPicture;
45+
46+
/// Converts this [OneSignalRequestBody] instance to a JSON map.
47+
Map<String, dynamic> toJson() => _$OneSignalRequestBodyToJson(this);
48+
49+
@override
50+
List<Object?> get props => [
51+
appId,
52+
includePlayerIds,
53+
headings,
54+
contents,
55+
data,
56+
bigPicture,
57+
];
58+
}

lib/src/models/push_notification/onesignal_request_body.g.dart

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'firebase_request_body.dart';
2+
export 'onesignal_request_body.dart';

lib/src/rbac/permissions.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ abstract class Permissions {
5050
static const String userUpdate = 'user.update';
5151

5252
// User App Settings Permissions (User-owned)
53-
static const String userAppSettingsReadOwned = 'user_app_settings.read_owned';
54-
static const String userAppSettingsUpdateOwned =
55-
'user_app_settings.update_owned';
53+
static const String appSettingsReadOwned = 'app_settings.read_owned';
54+
static const String appSettingsUpdateOwned = 'app_settings.update_owned';
5655

5756
// User Content Preferences Permissions (User-owned)
5857
static const String userContentPreferencesReadOwned =

lib/src/rbac/role_permissions.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ final Set<String> _appGuestUserPermissions = {
99
Permissions.sourceRead,
1010
Permissions.countryRead,
1111
Permissions.languageRead,
12-
Permissions.userAppSettingsReadOwned,
13-
Permissions.userAppSettingsUpdateOwned,
12+
Permissions.appSettingsReadOwned,
13+
Permissions.appSettingsUpdateOwned,
1414
Permissions.userContentPreferencesReadOwned,
1515
Permissions.userContentPreferencesUpdateOwned,
1616
Permissions.remoteConfigRead,

0 commit comments

Comments
 (0)