@@ -10,16 +10,13 @@ import 'package:ht_shared/ht_shared.dart';
10
10
class DashboardSummaryService {
11
11
/// {@macro dashboard_summary_service}
12
12
const DashboardSummaryService ({
13
- required HtDataRepository <User > userRepository,
14
13
required HtDataRepository <Headline > headlineRepository,
15
14
required HtDataRepository <Category > categoryRepository,
16
15
required HtDataRepository <Source > sourceRepository,
17
- }) : _userRepository = userRepository,
18
- _headlineRepository = headlineRepository,
16
+ }) : _headlineRepository = headlineRepository,
19
17
_categoryRepository = categoryRepository,
20
18
_sourceRepository = sourceRepository;
21
19
22
- final HtDataRepository <User > _userRepository;
23
20
final HtDataRepository <Headline > _headlineRepository;
24
21
final HtDataRepository <Category > _categoryRepository;
25
22
final HtDataRepository <Source > _sourceRepository;
@@ -29,13 +26,23 @@ class DashboardSummaryService {
29
26
/// This method fetches all items from the required repositories to count them
30
27
/// and constructs a [DashboardSummary] object.
31
28
Future <DashboardSummary > getSummary () async {
32
- // The actual calculation logic will be implemented in a subsequent step.
33
- // For now, this serves as a placeholder structure.
29
+ // Use Future.wait to fetch all counts in parallel for efficiency.
30
+ final results = await Future .wait ([
31
+ _headlineRepository.readAll (),
32
+ _categoryRepository.readAll (),
33
+ _sourceRepository.readAll (),
34
+ ]);
35
+
36
+ // The results are PaginatedResponse objects.
37
+ final headlineResponse = results[0 ] as PaginatedResponse <Headline >;
38
+ final categoryResponse = results[1 ] as PaginatedResponse <Category >;
39
+ final sourceResponse = results[2 ] as PaginatedResponse <Source >;
40
+
34
41
return DashboardSummary (
35
- id: 'dashboard_summary' ,
36
- headlineCount: 0 ,
37
- categoryCount: 0 ,
38
- sourceCount: 0 ,
42
+ id: 'dashboard_summary' , // Fixed ID for the singleton summary
43
+ headlineCount: headlineResponse.items.length ,
44
+ categoryCount: categoryResponse.items.length ,
45
+ sourceCount: sourceResponse.items.length ,
39
46
);
40
47
}
41
48
}
0 commit comments