diff --git a/pub_stats/lib/controller/user_controller.dart b/pub_stats/lib/controller/user_controller.dart index b4bda95..5bf4806 100644 --- a/pub_stats/lib/controller/user_controller.dart +++ b/pub_stats/lib/controller/user_controller.dart @@ -75,7 +75,7 @@ class UserController { /// Return true on success Future addConfig({ required String slug, - required AlertType type, + required AlertConfigType type, required String extra, required Set ignore, }) async { @@ -84,7 +84,7 @@ class UserController { } final AlertConfig config; - if (type == AlertType.discord) { + if (type == AlertConfigType.discord) { final match = RegExp(r'https:\/\/discord\.com\/api\/webhooks\/(.+)\/(.+)') .firstMatch(extra); @@ -94,7 +94,7 @@ class UserController { ); return false; } - config = DiscordConfig( + config = DiscordAlertConfig( slug: slug, ignore: ignore, id: match[1]!, diff --git a/pub_stats/lib/view/screen/alerts_manager.dart b/pub_stats/lib/view/screen/alerts_manager.dart index 87ef296..04c6e65 100644 --- a/pub_stats/lib/view/screen/alerts_manager.dart +++ b/pub_stats/lib/view/screen/alerts_manager.dart @@ -9,7 +9,7 @@ import 'package:recase/recase.dart'; class AlertsManager extends StatelessWidget { static final _user = GetIt.I(); - final selectedType = AlertType.discord.rx; + final selectedType = AlertConfigType.discord.rx; final slugController = TextEditingController(); final extraController = TextEditingController(); final ignoredFields = {}.rx; @@ -58,7 +58,7 @@ class AlertsManager extends StatelessWidget { border: OutlineInputBorder(), ), value: selectedType.value, - items: AlertType.values + items: AlertConfigType.values .map( (e) => DropdownMenuItem( value: e, @@ -181,7 +181,7 @@ class AlertsManager extends StatelessWidget { } void addConfig() async { - if (await _user.addConfig( + if (!await _user.addConfig( slug: slugController.text, ignore: ignoredFields, type: selectedType.value, diff --git a/pub_stats_core/lib/src/model/alert_config.dart b/pub_stats_core/lib/src/model/alert_config.dart index ec0dd84..b602653 100644 --- a/pub_stats_core/lib/src/model/alert_config.dart +++ b/pub_stats_core/lib/src/model/alert_config.dart @@ -11,7 +11,7 @@ abstract class AlertConfig { final Set ignore; /// The type of alert - final AlertType type; + final AlertConfigType type; AlertConfig({ required this.slug, @@ -20,18 +20,18 @@ abstract class AlertConfig { }); factory AlertConfig.fromJson(Map json) => - switch (AlertType.values.byName(json['type'])) { - AlertType.discord => DiscordConfig.fromJson(json), + switch (AlertConfigType.values.byName(json['type'])) { + AlertConfigType.discord => DiscordAlertConfig.fromJson(json), }; Map toJson(); String get extra => switch (type) { - AlertType.discord => (this as DiscordConfig).id, + AlertConfigType.discord => (this as DiscordAlertConfig).id, }; } -enum AlertType { +enum AlertConfigType { discord; String get extraLabel => switch (this) { @@ -42,21 +42,21 @@ enum AlertType { abstract class AlertServiceConfig {} @JsonSerializable() -class DiscordConfig extends AlertConfig { +class DiscordAlertConfig extends AlertConfig { final String id; final String token; - DiscordConfig({ + DiscordAlertConfig({ required super.slug, super.ignore, required this.id, required this.token, - super.type = AlertType.discord, - }) : assert(type == AlertType.discord); + super.type = AlertConfigType.discord, + }) : assert(type == AlertConfigType.discord); - factory DiscordConfig.fromJson(Map json) => - _$DiscordConfigFromJson(json); + factory DiscordAlertConfig.fromJson(Map json) => + _$DiscordAlertConfigFromJson(json); @override - Map toJson() => _$DiscordConfigToJson(this); + Map toJson() => _$DiscordAlertConfigToJson(this); } diff --git a/pub_stats_core/lib/src/model/alert_config.g.dart b/pub_stats_core/lib/src/model/alert_config.g.dart index 563fc54..4ab647c 100644 --- a/pub_stats_core/lib/src/model/alert_config.g.dart +++ b/pub_stats_core/lib/src/model/alert_config.g.dart @@ -8,8 +8,8 @@ part of 'alert_config.dart'; // JsonSerializableGenerator // ************************************************************************** -DiscordConfig _$DiscordConfigFromJson(Map json) => - DiscordConfig( +DiscordAlertConfig _$DiscordAlertConfigFromJson(Map json) => + DiscordAlertConfig( slug: json['slug'] as String, ignore: (json['ignore'] as List?) ?.map((e) => $enumDecode(_$PackageDataFieldEnumMap, e)) @@ -17,16 +17,16 @@ DiscordConfig _$DiscordConfigFromJson(Map json) => const {}, id: json['id'] as String, token: json['token'] as String, - type: $enumDecodeNullable(_$AlertTypeEnumMap, json['type']) ?? - AlertType.discord, + type: $enumDecodeNullable(_$AlertConfigTypeEnumMap, json['type']) ?? + AlertConfigType.discord, ); -Map _$DiscordConfigToJson(DiscordConfig instance) => +Map _$DiscordAlertConfigToJson(DiscordAlertConfig instance) => { 'slug': instance.slug, 'ignore': instance.ignore.map((e) => _$PackageDataFieldEnumMap[e]!).toList(), - 'type': _$AlertTypeEnumMap[instance.type]!, + 'type': _$AlertConfigTypeEnumMap[instance.type]!, 'id': instance.id, 'token': instance.token, }; @@ -37,6 +37,6 @@ const _$PackageDataFieldEnumMap = { PackageDataField.pubPoints: 'pubPoints', }; -const _$AlertTypeEnumMap = { - AlertType.discord: 'discord', +const _$AlertConfigTypeEnumMap = { + AlertConfigType.discord: 'discord', }; diff --git a/pub_stats_core/lib/src/model/package_data.dart b/pub_stats_core/lib/src/model/package_data.dart index 387646e..40f0a95 100644 --- a/pub_stats_core/lib/src/model/package_data.dart +++ b/pub_stats_core/lib/src/model/package_data.dart @@ -3,5 +3,5 @@ class PackageData {} enum PackageDataField { likeCount, popularityScore, - pubPoints, + pubPoints; } diff --git a/pub_stats_core/pubspec.yaml b/pub_stats_core/pubspec.yaml index b3484cf..2cf0c0a 100644 --- a/pub_stats_core/pubspec.yaml +++ b/pub_stats_core/pubspec.yaml @@ -8,7 +8,7 @@ environment: dependencies: equatable: ^2.0.5 http: ^1.1.0 - json_annotation: ^4.4.0 + json_annotation: ^4.8.1 pub_api_client: ^2.2.0 dev_dependencies: