1
- import 'dart:async' ;
2
- import 'dart:convert' ;
3
- import 'dart:io' ;
4
-
5
1
import 'package:dart_frog/dart_frog.dart' ;
6
2
import 'package:ht_api/src/middlewares/error_handler.dart' ;
7
- import 'package:ht_api/src/rbac/permission_service.dart' ; // Import PermissionService
3
+ import 'package:ht_api/src/rbac/permission_service.dart' ;
8
4
import 'package:ht_api/src/registry/model_registry.dart' ;
9
5
import 'package:ht_api/src/services/auth_service.dart' ;
10
6
import 'package:ht_api/src/services/auth_token_service.dart' ;
11
- import 'package:ht_api/src/services/default_user_preference_limit_service.dart' ; // Import DefaultUserPreferenceLimitService
7
+ import 'package:ht_api/src/services/default_user_preference_limit_service.dart' ;
12
8
import 'package:ht_api/src/services/jwt_auth_token_service.dart' ;
13
9
import 'package:ht_api/src/services/token_blacklist_service.dart' ;
14
- import 'package:ht_api/src/services/user_preference_limit_service.dart' ; // Import UserPreferenceLimitService interface
10
+ import 'package:ht_api/src/services/user_preference_limit_service.dart' ;
15
11
import 'package:ht_api/src/services/verification_code_storage_service.dart' ;
16
12
import 'package:ht_data_inmemory/ht_data_inmemory.dart' ;
17
13
import 'package:ht_data_repository/ht_data_repository.dart' ;
@@ -65,61 +61,11 @@ class RequestId {
65
61
final String id;
66
62
}
67
63
68
- // --- Helper Function to Load Fixtures ---
69
- // Note:
70
- // Error handling here is basic, consider more robust file checks.
71
- // ignore: unused_element
72
- Future <List <Map <String , dynamic >>> _loadFixture (String fileName) async {
73
- final path = 'lib/src/fixtures/$fileName ' ;
74
- try {
75
- final file = File (path);
76
- if (! file.existsSync ()) {
77
- print ('Warning: Fixture file not found at $path . Returning empty list.' );
78
- return [];
79
- }
80
- final content = await file.readAsString ();
81
- final decoded = jsonDecode (content) as List <dynamic >? ; // Allow null
82
- // Ensure items are maps
83
- return decoded? .whereType <Map <String , dynamic >>().toList () ?? [];
84
- } catch (e) {
85
- print ('Error loading or parsing fixture file $path : $e ' );
86
- return []; // Return empty on error to avoid crashing startup
87
- }
88
- }
89
-
90
64
// --- Repository Creation Logic ---
91
- // Synchronous fixture loader (use with caution)
92
- List <Map <String , dynamic >> _loadFixtureSync (String fileName) {
93
- final path = 'lib/src/fixtures/$fileName ' ;
94
- try {
95
- final file = File (path);
96
- if (! file.existsSync ()) {
97
- print ('Warning: Fixture file not found at $path . Returning empty list.' );
98
- return [];
99
- }
100
- final content = file.readAsStringSync ();
101
- final decoded = jsonDecode (content);
102
-
103
- if (decoded is Map <String , dynamic >) {
104
- // If it's a single object, wrap it in a list
105
- return [decoded];
106
- } else if (decoded is List <dynamic >) {
107
- // If it's a list, filter for maps and return
108
- return decoded.whereType <Map <String , dynamic >>().toList ();
109
- } else {
110
- print ('Error: Fixture file $path contains unexpected JSON type.' );
111
- return [];
112
- }
113
- } catch (e) {
114
- print ('Error loading or parsing fixture file $path : $e ' );
115
- return [];
116
- }
117
- }
118
-
119
65
HtDataRepository <Headline > _createHeadlineRepository () {
120
66
print ('Initializing Headline Repository...' );
121
67
final initialData =
122
- _loadFixtureSync ( 'headlines.json' ) .map (Headline .fromJson).toList ();
68
+ headlinesFixturesData .map (Headline .fromJson).toList ();
123
69
final client = HtDataInMemoryClient <Headline >(
124
70
toJson: (i) => i.toJson (),
125
71
getId: (i) => i.id,
@@ -132,7 +78,7 @@ HtDataRepository<Headline> _createHeadlineRepository() {
132
78
HtDataRepository <Category > _createCategoryRepository () {
133
79
print ('Initializing Category Repository...' );
134
80
final initialData =
135
- _loadFixtureSync ( 'categories.json' ) .map (Category .fromJson).toList ();
81
+ categoriesFixturesData .map (Category .fromJson).toList ();
136
82
final client = HtDataInMemoryClient <Category >(
137
83
toJson: (i) => i.toJson (),
138
84
getId: (i) => i.id,
@@ -145,7 +91,7 @@ HtDataRepository<Category> _createCategoryRepository() {
145
91
HtDataRepository <Source > _createSourceRepository () {
146
92
print ('Initializing Source Repository...' );
147
93
final initialData =
148
- _loadFixtureSync ( 'sources.json' ) .map (Source .fromJson).toList ();
94
+ sourcesFixturesData .map (Source .fromJson).toList ();
149
95
final client = HtDataInMemoryClient <Source >(
150
96
toJson: (i) => i.toJson (),
151
97
getId: (i) => i.id,
@@ -158,7 +104,7 @@ HtDataRepository<Source> _createSourceRepository() {
158
104
HtDataRepository <Country > _createCountryRepository () {
159
105
print ('Initializing Country Repository...' );
160
106
final initialData =
161
- _loadFixtureSync ( 'countries.json' ) .map (Country .fromJson).toList ();
107
+ countriesFixturesData .map (Country .fromJson).toList ();
162
108
final client = HtDataInMemoryClient <Country >(
163
109
toJson: (i) => i.toJson (),
164
110
getId: (i) => i.id,
@@ -194,12 +140,8 @@ HtDataRepository<UserContentPreferences>
194
140
195
141
HtDataRepository <AppConfig > _createAppConfigRepository () {
196
142
print ('Initializing AppConfig Repository...' );
197
- final fixtureData = _loadFixtureSync ('app_config.json' );
198
- if (fixtureData.isEmpty) {
199
- throw Exception ('Failed to load app_config.json fixture or it is empty.' );
200
- }
201
143
final initialData = [
202
- AppConfig .fromJson (fixtureData.first ),
144
+ AppConfig .fromJson (appConfigFixtureData ),
203
145
]; // Assuming one config
204
146
final client = HtDataInMemoryClient <AppConfig >(
205
147
toJson: (i) => i.toJson (),
0 commit comments