1- import 'dart:async' ;
2- import 'dart:convert' ;
3- import 'dart:io' ;
4-
51import 'package:dart_frog/dart_frog.dart' ;
62import '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' ;
84import 'package:ht_api/src/registry/model_registry.dart' ;
95import 'package:ht_api/src/services/auth_service.dart' ;
106import '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' ;
128import 'package:ht_api/src/services/jwt_auth_token_service.dart' ;
139import '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' ;
1511import 'package:ht_api/src/services/verification_code_storage_service.dart' ;
1612import 'package:ht_data_inmemory/ht_data_inmemory.dart' ;
1713import 'package:ht_data_repository/ht_data_repository.dart' ;
@@ -65,61 +61,11 @@ class RequestId {
6561 final String id;
6662}
6763
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-
9064// --- 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-
11965HtDataRepository <Headline > _createHeadlineRepository () {
12066 print ('Initializing Headline Repository...' );
12167 final initialData =
122- _loadFixtureSync ( 'headlines.json' ) .map (Headline .fromJson).toList ();
68+ headlinesFixturesData .map (Headline .fromJson).toList ();
12369 final client = HtDataInMemoryClient <Headline >(
12470 toJson: (i) => i.toJson (),
12571 getId: (i) => i.id,
@@ -132,7 +78,7 @@ HtDataRepository<Headline> _createHeadlineRepository() {
13278HtDataRepository <Category > _createCategoryRepository () {
13379 print ('Initializing Category Repository...' );
13480 final initialData =
135- _loadFixtureSync ( 'categories.json' ) .map (Category .fromJson).toList ();
81+ categoriesFixturesData .map (Category .fromJson).toList ();
13682 final client = HtDataInMemoryClient <Category >(
13783 toJson: (i) => i.toJson (),
13884 getId: (i) => i.id,
@@ -145,7 +91,7 @@ HtDataRepository<Category> _createCategoryRepository() {
14591HtDataRepository <Source > _createSourceRepository () {
14692 print ('Initializing Source Repository...' );
14793 final initialData =
148- _loadFixtureSync ( 'sources.json' ) .map (Source .fromJson).toList ();
94+ sourcesFixturesData .map (Source .fromJson).toList ();
14995 final client = HtDataInMemoryClient <Source >(
15096 toJson: (i) => i.toJson (),
15197 getId: (i) => i.id,
@@ -158,7 +104,7 @@ HtDataRepository<Source> _createSourceRepository() {
158104HtDataRepository <Country > _createCountryRepository () {
159105 print ('Initializing Country Repository...' );
160106 final initialData =
161- _loadFixtureSync ( 'countries.json' ) .map (Country .fromJson).toList ();
107+ countriesFixturesData .map (Country .fromJson).toList ();
162108 final client = HtDataInMemoryClient <Country >(
163109 toJson: (i) => i.toJson (),
164110 getId: (i) => i.id,
@@ -194,12 +140,8 @@ HtDataRepository<UserContentPreferences>
194140
195141HtDataRepository <AppConfig > _createAppConfigRepository () {
196142 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- }
201143 final initialData = [
202- AppConfig .fromJson (fixtureData.first ),
144+ AppConfig .fromJson (appConfigFixtureData ),
203145 ]; // Assuming one config
204146 final client = HtDataInMemoryClient <AppConfig >(
205147 toJson: (i) => i.toJson (),
0 commit comments