Skip to content

Commit be5b899

Browse files
committed
fix(api): align summary service with correct model structure
1 parent 4133a82 commit be5b899

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/src/services/dashboard_summary_service.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ import 'package:ht_shared/ht_shared.dart';
1010
class DashboardSummaryService {
1111
/// {@macro dashboard_summary_service}
1212
const DashboardSummaryService({
13-
required HtDataRepository<User> userRepository,
1413
required HtDataRepository<Headline> headlineRepository,
1514
required HtDataRepository<Category> categoryRepository,
1615
required HtDataRepository<Source> sourceRepository,
17-
}) : _userRepository = userRepository,
18-
_headlineRepository = headlineRepository,
16+
}) : _headlineRepository = headlineRepository,
1917
_categoryRepository = categoryRepository,
2018
_sourceRepository = sourceRepository;
2119

22-
final HtDataRepository<User> _userRepository;
2320
final HtDataRepository<Headline> _headlineRepository;
2421
final HtDataRepository<Category> _categoryRepository;
2522
final HtDataRepository<Source> _sourceRepository;
@@ -29,13 +26,23 @@ class DashboardSummaryService {
2926
/// This method fetches all items from the required repositories to count them
3027
/// and constructs a [DashboardSummary] object.
3128
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+
3441
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,
3946
);
4047
}
4148
}

0 commit comments

Comments
 (0)