Skip to content

Commit 22ecbd0

Browse files
committed
feat(data_operation_registry): enhance country model filtering
- Add support for standard pagination/sorting for country model - Implement conditional logic to handle 'usage' filter for country model - Maintain backwards compatibility for existing specialized queries - Improve code readability and structure in data operation registry
1 parent a45102d commit 22ecbd0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

lib/src/registry/data_operation_registry.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,26 @@ class DataOperationRegistry {
130130
pagination: p,
131131
),
132132
'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-
);
133+
final usage = f?['usage'] as String?;
134+
if (usage != null && usage.isNotEmpty) {
135+
// For 'country' model with 'usage' filter, delegate to CountryService.
136+
// Sorting and pagination are not supported for this specialized query.
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+
} else {
145+
// For standard requests, use the repository which supports pagination/sorting.
146+
return c.read<DataRepository<Country>>().readAll(
147+
userId: uid,
148+
filter: f,
149+
sort: s,
150+
pagination: p,
151+
);
152+
}
144153
},
145154
'language': (c, uid, f, s, p) => c
146155
.read<DataRepository<Language>>()

0 commit comments

Comments
 (0)