Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit 821472d

Browse files
committed
docs: update README.md with filtering examples
- Updated filtering description - Added filtering code examples - Added create/update examples
1 parent 9d06dcf commit 821472d

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fetching, creating, updating, deleting, and searching headlines.
44

55
## Features
66

7-
- **Fetch Headlines:** Retrieve a paginated list of news headlines. Supports optional filtering by category, source, and event country.
7+
- **Fetch Headlines:** Retrieve a paginated list of news headlines. Supports optional filtering using lists of `Category`, `Source`, and `Country` objects. Filtering logic is OR within each list and AND across different filter types (e.g., (category A OR B) AND (source X OR Y)).
88
- **Get Headline by ID:** Fetch a specific headline by its unique identifier.
99
- **Create Headline:** Add a new headline to the data source.
1010
- **Update Headline:** Modify an existing headline in the data source.
@@ -52,11 +52,17 @@ void main() async {
5252
final headlinesPage1 = await headlinesRepository.getHeadlines(limit: 10);
5353
print('Page 1: ${headlinesPage1.items}');
5454
55-
// Fetch headlines with filtering
55+
// Fetch headlines with filtering (Example)
56+
// Assume you have Category, Source, Country objects available
57+
final techCategory = Category(id: 'tech', name: 'Technology');
58+
final bbcSource = Source(id: 'bbc', name: 'BBC News');
59+
final usCountry = Country(id: 'us', isoCode: 'US', name: 'United States', flagUrl: '');
60+
5661
final filteredHeadlines = await headlinesRepository.getHeadlines(
5762
limit: 5,
58-
category: 'technology',
59-
source: 'TechCrunch',
63+
categories: [techCategory], // Pass a list of Category objects
64+
sources: [bbcSource], // Pass a list of Source objects
65+
eventCountries: [usCountry], // Pass a list of Country objects
6066
);
6167
print('Filtered Headlines: ${filteredHeadlines.items}');
6268
@@ -86,9 +92,12 @@ void main() async {
8692
}
8793
8894
// --- createHeadline ---
95+
// Assume Category, Source, Country objects are available if needed
96+
final generalCategory = Category(id: 'gen', name: 'General');
97+
8998
try {
9099
final newHeadline = Headline(
91-
id: 'new_id',
100+
id: 'new_id', // ID is usually generated if not provided
92101
title: 'New Headline',
93102
description: 'This is a new headline.',
94103
url: 'https://example.com/new-headline',
@@ -103,14 +112,23 @@ void main() async {
103112
104113
// --- updateHeadline ---
105114
try {
106-
final updatedHeadline = Headline(
107-
id: 'existing_id', // Replace with an existing headline ID
108-
title: 'Updated Headline',
115+
// Fetch or create the headline object you want to update
116+
final existingHeadline = await headlinesRepository.getHeadline(id: 'existing_id');
117+
if (existingHeadline == null) {
118+
print('Headline to update not found.');
119+
return;
120+
}
121+
final updatedHeadlineData = existingHeadline.copyWith(
122+
title: 'Updated Headline Title',
109123
description: 'This headline has been updated.',
124+
// Update other fields as needed, e.g., category
125+
category: generalCategory,
110126
);
111127
final result =
112-
await headlinesRepository.updateHeadline(headline: updatedHeadline);
128+
await headlinesRepository.updateHeadline(headline: updatedHeadlineData);
113129
print('Updated Headline: $result');
130+
} on HeadlineNotFoundException catch (e) {
131+
print('Error updating headline (not found): $e');
114132
} on HeadlineUpdateException catch (e) {
115133
print('Error updating headline: $e');
116134
}

0 commit comments

Comments
 (0)