Skip to content

Commit 3f56f39

Browse files
committed
refactor(country): implement specialized filtering for country model
- Replace generic DataRepository readAll method with CountryService for country model - Add support for 'usage' filter in country data operation - Return PaginatedResponse to maintain consistency with generic API structure - Remove unnecessary parameters (uid, s, p) from the custom operation
1 parent d4a13dc commit 3f56f39

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/src/registry/data_operation_registry.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:core/core.dart';
22
import 'package:dart_frog/dart_frog.dart';
33
import 'package:data_repository/data_repository.dart';
44
import 'package:flutter_news_app_api_server_full_source_code/src/middlewares/ownership_check_middleware.dart';
5+
import 'package:flutter_news_app_api_server_full_source_code/src/services/country_service.dart';
56
import 'package:flutter_news_app_api_server_full_source_code/src/services/dashboard_summary_service.dart';
67

78
// --- Typedefs for Data Operations ---
@@ -128,12 +129,19 @@ class DataOperationRegistry {
128129
sort: s,
129130
pagination: p,
130131
),
131-
'country': (c, uid, f, s, p) => c.read<DataRepository<Country>>().readAll(
132-
userId: uid,
133-
filter: f,
134-
sort: s,
135-
pagination: p,
136-
),
132+
'country': (c, uid, f, s, p) async {
133+
// For 'country' model, delegate to CountryService for specialized filtering.
134+
// The CountryService handles the 'usage' filter and returns a List<Country>.
135+
// We then wrap this list in a PaginatedResponse for consistency with
136+
// the generic API response structure.
137+
final countryService = c.read<CountryService>();
138+
final countries = await countryService.getCountries(f);
139+
return PaginatedResponse<Country>(
140+
items: countries,
141+
cursor: null, // No cursor for this type of filtered list
142+
hasMore: false, // No more items as it's a complete filtered set
143+
);
144+
},
137145
'language': (c, uid, f, s, p) => c
138146
.read<DataRepository<Language>>()
139147
.readAll(userId: uid, filter: f, sort: s, pagination: p),

0 commit comments

Comments
 (0)