Skip to content

Commit b1278a0

Browse files
committed
refactor(api): integrate dashboard summary service into middleware
1 parent be5b899 commit b1278a0

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

routes/_middleware.dart

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:ht_api/src/registry/model_registry.dart';
55
import 'package:ht_api/src/services/auth_service.dart';
66
import 'package:ht_api/src/services/auth_token_service.dart';
77
import 'package:ht_api/src/services/default_user_preference_limit_service.dart';
8+
import 'package:ht_api/src/services/dashboard_summary_service.dart';
89
import 'package:ht_api/src/services/jwt_auth_token_service.dart';
910
import 'package:ht_api/src/services/token_blacklist_service.dart';
1011
import 'package:ht_api/src/services/user_preference_limit_service.dart';
@@ -148,20 +149,6 @@ HtDataRepository<AppConfig> _createAppConfigRepository() {
148149
return HtDataRepository<AppConfig>(dataClient: client);
149150
}
150151

151-
HtDataRepository<DashboardSummary> _createDashboardSummaryRepository() {
152-
print('Initializing DashboardSummary Repository...');
153-
final initialData = [
154-
DashboardSummary.fromJson(dashboardSummaryFixtureData),
155-
];
156-
final client = HtDataInMemory<DashboardSummary>(
157-
toJson: (i) => i.toJson(),
158-
getId: (i) => i.id,
159-
initialData: initialData,
160-
);
161-
print('DashboardSummary Repository Initialized.');
162-
return HtDataRepository<DashboardSummary>(dataClient: client);
163-
}
164-
165152
/// Middleware to asynchronously load and provide the AppConfig.
166153
Middleware _appConfigProviderMiddleware() {
167154
return (handler) {
@@ -188,7 +175,14 @@ Handler middleware(Handler handler) {
188175
final userContentPreferencesRepository =
189176
_createUserContentPreferencesRepository();
190177
final appConfigRepository = _createAppConfigRepository();
191-
final dashboardSummaryRepository = _createDashboardSummaryRepository();
178+
179+
// Instantiate the new DashboardSummaryService with its dependencies
180+
final dashboardSummaryService = DashboardSummaryService(
181+
headlineRepository: headlineRepository,
182+
categoryRepository: categoryRepository,
183+
sourceRepository: sourceRepository,
184+
);
185+
print('[MiddlewareSetup] DashboardSummaryService instantiated.');
192186

193187
const uuid = Uuid();
194188

@@ -301,11 +295,6 @@ Handler middleware(Handler handler) {
301295
),
302296
)
303297
.use(provider<HtDataRepository<AppConfig>>((_) => appConfigRepository))
304-
.use(
305-
provider<HtDataRepository<DashboardSummary>>(
306-
(_) => dashboardSummaryRepository,
307-
),
308-
)
309298
// ORDER: These MUST be provided BEFORE `authenticationProvider` and
310299
// any route handlers that perform authentication/authorization.
311300
// - `Uuid` is used by `AuthService` and `JwtAuthTokenService`.
@@ -328,6 +317,7 @@ Handler middleware(Handler handler) {
328317
.use(
329318
provider<AuthService>((_) => authService),
330319
) // Reads other services/repos
320+
.use(provider<DashboardSummaryService>((_) => dashboardSummaryService))
331321
// --- 5. RBAC Service Provider ---
332322
// PURPOSE: Provides the PermissionService for authorization checks.
333323
// ORDER: Must be provided before any middleware or handlers that use it

0 commit comments

Comments
 (0)