Skip to content

Commit 6dd0eb8

Browse files
committed
refactor: load app config from JSON fixture
- Loads app config from app_config.json - Uses AppConfig.fromJson for parsing - Inits repository with parsed config
1 parent 9e9f848 commit 6dd0eb8

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

lib/src/fixtures/app_config.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"id": "app_config",
3+
"user_preference_limits": {
4+
"guest_followed_items_limit": 5,
5+
"guest_saved_headlines_limit": 10,
6+
"authenticated_followed_items_limit": 15,
7+
"authenticated_saved_headlines_limit": 30,
8+
"premium_followed_items_limit": 30,
9+
"premium_saved_headlines_limit": 100
10+
},
11+
"ad_config": {
12+
"guest_ad_frequency": 5,
13+
"guest_ad_placement_interval": 3,
14+
"authenticated_ad_frequency": 10,
15+
"authenticated_ad_placement_interval": 5,
16+
"premium_ad_frequency": 0,
17+
"premium_ad_placement_interval": 0
18+
},
19+
"engagement_rules": [
20+
{
21+
"template_type": "rate-app",
22+
"user_roles": ["standard_user"],
23+
"min_days_since_account_creation": 7,
24+
"max_times_to_show": 1,
25+
"min_days_since_last_shown": 30,
26+
"placement": {
27+
"after_primary_item_index": 5,
28+
"min_primary_items_required": 10
29+
}
30+
},
31+
{
32+
"template_type": "link-account",
33+
"user_roles": ["guest_user"],
34+
"min_days_since_account_creation": 3,
35+
"max_times_to_show": 3,
36+
"min_days_since_last_shown": 7,
37+
"placement": {
38+
"after_primary_item_index": 3,
39+
"min_primary_items_required": 5
40+
}
41+
},
42+
{
43+
"template_type": "upgrade-to-premium",
44+
"user_roles": ["standard_user"],
45+
"min_days_since_account_creation": 14,
46+
"max_times_to_show": 2,
47+
"min_days_since_last_shown": 15,
48+
"placement": {
49+
"relative_position": "middle",
50+
"min_primary_items_required": 10
51+
}
52+
}
53+
],
54+
"suggestion_rules": [
55+
{
56+
"template_type": "categories-to-follow",
57+
"user_roles": ["guest_user", "standard_user"],
58+
"placement": {
59+
"after_primary_item_index": 7,
60+
"min_primary_items_required": 10
61+
}
62+
},
63+
{
64+
"template_type": "sources-to-follow",
65+
"user_roles": ["standard_user"],
66+
"placement": {
67+
"relative_position": "end_quarter",
68+
"min_primary_items_required": 15
69+
}
70+
}
71+
]
72+
}

routes/_middleware.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ HtDataRepository<UserContentPreferences>
184184

185185
HtDataRepository<AppConfig> _createAppConfigRepository() {
186186
print('Initializing AppConfig Repository...');
187-
// AppConfig should have a single instance, potentially loaded from a file
188-
// or created with defaults if not found. For in-memory, we can create a
189-
// default instance.
187+
final fixtureData = _loadFixtureSync('app_config.json');
188+
if (fixtureData.isEmpty) {
189+
throw Exception('Failed to load app_config.json fixture or it is empty.');
190+
}
190191
final initialData = [
191-
const AppConfig(id: 'app_config'), // Default config
192-
];
192+
AppConfig.fromJson(fixtureData.first),
193+
]; // Assuming one config
193194
final client = HtDataInMemoryClient<AppConfig>(
194195
toJson: (i) => i.toJson(),
195196
getId: (i) => i.id,

0 commit comments

Comments
 (0)