Skip to content

Commit 223f78c

Browse files
committed
refactor: remove automated de/serialization
1 parent ae1bb4c commit 223f78c

22 files changed

+118
-119
lines changed

lib/src/models/feed/ad.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/src/models/feed/ad_placement.dart';
32
import 'package:ht_shared/src/models/feed/feed_item.dart';
43
import 'package:ht_shared/src/models/feed/feed_item_action.dart';
@@ -70,7 +69,7 @@ class Ad extends FeedItem {
7069
/// Converts this [Ad] instance to a JSON map.
7170
@override
7271
Map<String, dynamic> toJson() {
73-
final Map<String, dynamic> json = {
72+
final json = <String, dynamic>{
7473
'id': id,
7574
'imageUrl': imageUrl,
7675
'targetUrl': targetUrl,

lib/src/models/feed/engagement_content.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/src/models/feed/engagement_content_type.dart';
32
import 'package:ht_shared/src/models/feed/feed_item.dart';
43
import 'package:ht_shared/src/models/feed/feed_item_action.dart';
@@ -23,7 +22,9 @@ class EngagementContent extends FeedItem {
2322
this.callToActionUrl,
2423
String? id,
2524
}) : id = id ?? const Uuid().v4(),
26-
super(type: 'engagement_content'); // Removed action from super constructor
25+
super(
26+
type:
27+
'engagement_content',); // Removed action from super constructor
2728

2829
/// Factory method to create an [EngagementContent] instance from a JSON map.
2930
factory EngagementContent.fromJson(Map<String, dynamic> json) {
@@ -61,7 +62,7 @@ class EngagementContent extends FeedItem {
6162
/// Converts this [EngagementContent] instance to a JSON map.
6263
@override
6364
Map<String, dynamic> toJson() {
64-
final Map<String, dynamic> json = {
65+
final json = <String, dynamic>{
6566
'id': id,
6667
'title': title,
6768
'description': description,

lib/src/models/feed/suggested_content.dart

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/ht_shared.dart'
32
show Category, Country, Headline, Source;
43
import 'package:ht_shared/src/models/feed/feed_item.dart';
@@ -25,7 +24,8 @@ class SuggestedContent extends FeedItem {
2524
this.description,
2625
String? id,
2726
}) : id = id ?? const Uuid().v4(),
28-
super(type: 'suggested_content'); // Removed action from super constructor
27+
super(
28+
type: 'suggested_content',); // Removed action from super constructor
2929

3030
/// Factory method to create a [SuggestedContent] instance from a JSON map.
3131
factory SuggestedContent.fromJson(Map<String, dynamic> json) {
@@ -36,24 +36,22 @@ class SuggestedContent extends FeedItem {
3636
displayType: suggestedContentDisplayTypeFromJson(
3737
json['displayType'] as String,
3838
),
39-
items: (json['items'] as List<dynamic>)
40-
.map((e) {
41-
final itemMap = e as Map<String, dynamic>;
42-
final itemType = itemMap['type'] as String;
43-
switch (itemType) {
44-
case 'headline':
45-
return Headline.fromJson(itemMap);
46-
case 'category':
47-
return Category.fromJson(itemMap);
48-
case 'source':
49-
return Source.fromJson(itemMap);
50-
case 'country':
51-
return Country.fromJson(itemMap);
52-
default:
53-
throw FormatException('Unknown item type: $itemType');
54-
}
55-
})
56-
.toList(),
39+
items: (json['items'] as List<dynamic>).map((e) {
40+
final itemMap = e as Map<String, dynamic>;
41+
final itemType = itemMap['type'] as String;
42+
switch (itemType) {
43+
case 'headline':
44+
return Headline.fromJson(itemMap);
45+
case 'category':
46+
return Category.fromJson(itemMap);
47+
case 'source':
48+
return Source.fromJson(itemMap);
49+
case 'country':
50+
return Country.fromJson(itemMap);
51+
default:
52+
throw FormatException('Unknown item type: $itemType');
53+
}
54+
}).toList(),
5755
action: FeedItemAction.fromJson(json['action'] as Map<String, dynamic>),
5856
);
5957
}
@@ -77,7 +75,7 @@ class SuggestedContent extends FeedItem {
7775
/// Converts this [SuggestedContent] instance to a JSON map.
7876
@override
7977
Map<String, dynamic> toJson() {
80-
final Map<String, dynamic> json = {
78+
final json = <String, dynamic>{
8179
'id': id,
8280
'title': title,
8381
'description': description,
@@ -92,7 +90,8 @@ class SuggestedContent extends FeedItem {
9290
} else if (e is Country) {
9391
return e.toJson();
9492
}
95-
throw FormatException('Unknown item type for serialization: ${e.runtimeType}');
93+
throw FormatException(
94+
'Unknown item type for serialization: ${e.runtimeType}',);
9695
}).toList(),
9796
'action': action.toJson(),
9897
'type': type, // Inherited from FeedItem

lib/src/models/models.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export '../utils/json_converters.dart';
12
export 'feed/feed.dart';
23
export 'news/news.dart';
34
export 'permission.dart';
@@ -7,4 +8,3 @@ export 'user-preferences/user_preferences.dart';
78
export 'user-settings/user_settings.dart';
89
export 'user.dart';
910
export 'user_role.dart';
10-
export '../utils/json_converters.dart';

lib/src/models/news/category.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/src/models/feed/feed_item.dart';
32
import 'package:ht_shared/src/models/feed/feed_item_action.dart';
43
import 'package:meta/meta.dart';

lib/src/models/news/country.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/src/models/feed/feed_item.dart';
32
import 'package:ht_shared/src/models/feed/feed_item_action.dart';
43
import 'package:uuid/uuid.dart';
@@ -43,7 +42,6 @@ class Country extends FeedItem {
4342
/// The URL pointing to an image of the country's flag.
4443
final String flagUrl;
4544

46-
4745
/// Converts this Country instance into a JSON map.
4846
@override
4947
Map<String, dynamic> toJson() {

lib/src/models/news/headline.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/src/models/feed/feed_item.dart';
32
import 'package:ht_shared/src/models/feed/feed_item_action.dart';
43
import 'package:ht_shared/src/models/news/category.dart';
@@ -83,7 +82,7 @@ class Headline extends FeedItem {
8382
/// Converts this [Headline] instance to a JSON map.
8483
@override
8584
Map<String, dynamic> toJson() {
86-
final Map<String, dynamic> json = {
85+
final json = <String, dynamic>{
8786
'id': id,
8887
'title': title,
8988
'description': description,

lib/src/models/news/source.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:equatable/equatable.dart';
21
import 'package:ht_shared/src/models/feed/feed_item.dart';
32
import 'package:ht_shared/src/models/feed/feed_item_action.dart';
43
import 'package:ht_shared/src/models/feed/source_type.dart';
@@ -74,7 +73,7 @@ class Source extends FeedItem {
7473
/// Converts this [Source] instance to a JSON map.
7574
@override
7675
Map<String, dynamic> toJson() {
77-
final Map<String, dynamic> json = {
76+
final json = <String, dynamic>{
7877
'id': id,
7978
'name': name,
8079
'description': description,

lib/src/models/remote-config/ad_config.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import 'package:equatable/equatable.dart';
2+
import 'package:ht_shared/ht_shared.dart' show AppConfig;
3+
import 'package:ht_shared/src/models/models.dart' show AppConfig;
4+
import 'package:ht_shared/src/models/remote-config/app_config.dart' show AppConfig;
5+
import 'package:ht_shared/src/models/remote-config/remote_config.dart' show AppConfig;
26

37
/// {@template ad_config}
48
/// Defines configuration settings related to ad injection and display,

lib/src/models/remote-config/user_preference_limits.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:equatable/equatable.dart';
2+
import 'package:ht_shared/ht_shared.dart' show AppConfig, UserContentPreferences;
3+
import 'package:ht_shared/src/models/models.dart' show AppConfig, UserContentPreferences;
24
import 'package:meta/meta.dart';
35

46
/// {@template user_preference_limits}

0 commit comments

Comments
 (0)