2
2
3
3
import 'package:dart_frog/dart_frog.dart' ;
4
4
import 'package:ht_api/src/config/environment_config.dart' ;
5
+ import 'package:ht_api/src/rbac/permission_service.dart' ;
6
+ import 'package:ht_api/src/services/auth_service.dart' ;
7
+ import 'package:ht_api/src/services/auth_token_service.dart' ;
8
+ import 'package:ht_api/src/services/dashboard_summary_service.dart' ;
9
+ import 'package:ht_api/src/services/default_user_preference_limit_service.dart' ;
10
+ import 'package:ht_api/src/services/jwt_auth_token_service.dart' ;
11
+ import 'package:ht_api/src/services/token_blacklist_service.dart' ;
12
+ import 'package:ht_api/src/services/user_preference_limit_service.dart' ;
13
+ import 'package:ht_api/src/services/verification_code_storage_service.dart' ;
5
14
import 'package:ht_data_client/ht_data_client.dart' ;
6
15
import 'package:ht_data_postgres/ht_data_postgres.dart' ;
7
16
import 'package:ht_data_repository/ht_data_repository.dart' ;
17
+ import 'package:ht_email_inmemory/ht_email_inmemory.dart' ;
18
+ import 'package:ht_email_repository/ht_email_repository.dart' ;
8
19
import 'package:ht_shared/ht_shared.dart' ;
9
20
import 'package:logging/logging.dart' ;
10
21
import 'package:postgres/postgres.dart' ;
@@ -124,9 +135,43 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
124
135
toJson: (c) => c.toJson (),
125
136
);
126
137
127
- // 4. Create the main handler with all dependencies provided
138
+ // 4. Initialize Services
139
+ const uuid = Uuid ();
140
+ const emailRepository = HtEmailRepository (
141
+ emailClient: HtEmailInMemoryClient (),
142
+ );
143
+ final tokenBlacklistService = InMemoryTokenBlacklistService ();
144
+ final authTokenService = JwtAuthTokenService (
145
+ userRepository: userRepository,
146
+ blacklistService: tokenBlacklistService,
147
+ uuidGenerator: uuid,
148
+ );
149
+ final verificationCodeStorageService =
150
+ InMemoryVerificationCodeStorageService ();
151
+ final authService = AuthService (
152
+ userRepository: userRepository,
153
+ authTokenService: authTokenService,
154
+ verificationCodeStorageService: verificationCodeStorageService,
155
+ emailRepository: emailRepository,
156
+ userAppSettingsRepository: userAppSettingsRepository,
157
+ userContentPreferencesRepository: userContentPreferencesRepository,
158
+ uuidGenerator: uuid,
159
+ );
160
+ final dashboardSummaryService = DashboardSummaryService (
161
+ headlineRepository: headlineRepository,
162
+ categoryRepository: categoryRepository,
163
+ sourceRepository: sourceRepository,
164
+ );
165
+ const permissionService = PermissionService ();
166
+ final userPreferenceLimitService = DefaultUserPreferenceLimitService (
167
+ appConfigRepository: appConfigRepository,
168
+ );
169
+
170
+ // 5. Create the main handler with all dependencies provided
128
171
final finalHandler = handler
129
- .use (provider <Uuid >((_) => const Uuid ()))
172
+ // Foundational utilities
173
+ .use (provider <Uuid >((_) => uuid))
174
+ // Repositories
130
175
.use (provider <HtDataRepository <Headline >>((_) => headlineRepository))
131
176
.use (provider <HtDataRepository <Category >>((_) => categoryRepository))
132
177
.use (provider <HtDataRepository <Source >>((_) => sourceRepository))
@@ -142,17 +187,34 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
142
187
(_) => userContentPreferencesRepository,
143
188
),
144
189
)
145
- .use (provider <HtDataRepository <AppConfig >>((_) => appConfigRepository));
190
+ .use (provider <HtDataRepository <AppConfig >>((_) => appConfigRepository))
191
+ .use (provider <HtEmailRepository >((_) => emailRepository))
192
+ // Services
193
+ .use (provider <TokenBlacklistService >((_) => tokenBlacklistService))
194
+ .use (provider <AuthTokenService >((_) => authTokenService))
195
+ .use (
196
+ provider <VerificationCodeStorageService >(
197
+ (_) => verificationCodeStorageService,
198
+ ),
199
+ )
200
+ .use (provider <AuthService >((_) => authService))
201
+ .use (provider <DashboardSummaryService >((_) => dashboardSummaryService))
202
+ .use (provider <PermissionService >((_) => permissionService))
203
+ .use (
204
+ provider <UserPreferenceLimitService >(
205
+ (_) => userPreferenceLimitService,
206
+ ),
207
+ );
146
208
147
- // 5 . Start the server
209
+ // 6 . Start the server
148
210
final server = await serve (
149
211
finalHandler,
150
212
ip,
151
213
port,
152
214
);
153
215
_log.info ('Server listening on port ${server .port }' );
154
216
155
- // 6 . Handle graceful shutdown
217
+ // 7 . Handle graceful shutdown
156
218
ProcessSignal .sigint.watch ().listen ((_) async {
157
219
_log.info ('Received SIGINT. Shutting down...' );
158
220
await _connection.close ();
0 commit comments