Skip to content

Commit f083d33

Browse files
authored
Merge branch 'main' into dependabot/pub/meta-1.17.0
2 parents e18c166 + 0ac8920 commit f083d33

File tree

63 files changed

+1754
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1754
-125
lines changed

README.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# ht_shared
22

3-
![coverage: percentage](https://img.shields.io/badge/coverage-93-green)
3+
![coverage: percentage](https://img.shields.io/badge/coverage-97-green)
44
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
55
[![License: PolyForm Free Trial](https://img.shields.io/badge/License-PolyForm%20Free%20Trial-blue)](https://polyformproject.org/licenses/free-trial/1.0.0)
66

7-
A shared Dart package containing core data models for news-related entities (like headlines, sources, categories, countries), pagination, and standardized API response structures, used across the application ecosystem (Mobile App, Backend API, Web Dashboard).
7+
A shared Dart package containing core data models for news-related entities (like headlines, sources, categories, countries), pagination, standardized API response structures, **user content preferences**, and **application configuration**, used across the application ecosystem (Mobile App, Backend API, Web Dashboard).
88

99
## Getting Started
1010

@@ -27,7 +27,11 @@ This package provides the following core data models:
2727
* **`Category`**: Represents a news category with an ID, name, and optional description and icon URL.
2828
* **`Source`**: Represents a news source, including ID, name, description, URL, language, optional headquarters (`Country`), and a `SourceType` enum (e.g., `newsAgency`, `blog`).
2929
* **`Country`**: Represents a country with an ID, ISO code, name, and flag URL.
30-
* **`User`**: Represents an authenticated user within the system, including an `isAdmin` flag.
30+
* **`UserContentPreferences`**: Represents a collection of user-specific content preferences, including followed countries, sources, categories, and saved headlines. This model stores full objects for these items and is subject to tiered limits based on user role.
31+
* **`AppConfig`**: Represents the overall application configuration. This model serves as a central container for various configuration settings, including user preference limits, and is designed to be fetched and managed via the `HtDataClient`.
32+
* **`UserPreferenceLimits`**: Defines the maximum number of items a user can follow or save, tiered by user role (Guest, Authenticated, Premium). This model is part of the `AppConfig` and is used for backend enforcement and client-side UI/UX.
33+
* **`UserAppSettings`**: Represents a collection of user-specific application settings, unifying display preferences (`DisplaySettings`) and language selection (`AppLanguage`). This model is designed for management via a generic data client (`HtDataClient`).
34+
* **`User`**: Represents a user within the system, including their assigned `role`.
3135
* **`PaginatedResponse<T>`**: A generic class for handling paginated API responses, containing a list of items (`items`), a `cursor` for the next page, and a `hasMore` flag.
3236
* **`AuthSuccessResponse`**: Represents the successful result of an authentication operation, typically containing the authenticated user details and an access token.
3337
* **`SuccessApiResponse<T>`**: A generic wrapper for successful API responses, containing the main `data` payload (of type `T`) and optional `ResponseMetadata`.
@@ -51,6 +55,7 @@ void main() {
5155
);
5256
5357
final headline = Headline(
58+
id: 'headline-1', // Added ID for clarity in preferences example
5459
title: 'New Gadget Announced',
5560
description: 'A revolutionary new device changes everything.',
5661
url: 'https://techcrunch.com/news/new-gadget',
@@ -61,6 +66,48 @@ void main() {
6166
6267
print('Headline: ${headline.title} from ${headline.source?.name}');
6368
69+
// Example: Creating User Content Preferences
70+
final userPreferences = UserContentPreferences(
71+
id: 'user-abc',
72+
followedCountries: [
73+
Country(id: 'us', isoCode: 'US', name: 'United States', flagUrl: '...'),
74+
Country(id: 'gb', isoCode: 'GB', name: 'United Kingdom', flagUrl: '...'),
75+
],
76+
followedSources: [
77+
source, // Using the source created above
78+
Source(id: 'bbc', name: 'BBC News', type: SourceType.nationalNewsOutlet),
79+
],
80+
followedCategories: [
81+
Category(id: 'sports', name: 'Sports'),
82+
Category(id: 'business', name: 'Business'),
83+
],
84+
savedHeadlines: [
85+
headline, // Saving the headline created above
86+
Headline(id: 'headline-2', title: 'Another Saved Article'),
87+
],
88+
);
89+
90+
print('\nUser ${userPreferences.id} follows ${userPreferences.followedSources.length} sources.');
91+
print('User ${userPreferences.id} has ${userPreferences.savedHeadlines.length} saved headlines.');
92+
93+
// Example: Accessing Application Configuration and User Preference Limits
94+
const appConfig = AppConfig(
95+
id: 'app_config',
96+
userPreferenceLimits: UserPreferenceLimits(
97+
guestFollowedItemsLimit: 5,
98+
guestSavedHeadlinesLimit: 10,
99+
authenticatedFollowedItemsLimit: 15,
100+
authenticatedSavedHeadlinesLimit: 30,
101+
premiumFollowedItemsLimit: 30,
102+
premiumSavedHeadlinesLimit: 100,
103+
),
104+
);
105+
106+
print('\nApp Config ID: ${appConfig.id}');
107+
print('Premium user saved headlines limit: ${appConfig.userPreferenceLimits.premiumSavedHeadlinesLimit}');
108+
109+
// Example: Representing a paginated response of Headlines
110+
64111
// Example: Representing a paginated response of Headlines
65112
final response = PaginatedResponse<Headline>(
66113
items: [headline],

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include: package:very_good_analysis/analysis_options.7.0.0.yaml
22
analyzer:
33
errors:
4+
document_ignores: ignore
45
lines_longer_than_80_chars: ignore
56
no_runtimetype_tostring: ignore
7+
unnecessary_null_checks: ignore

lib/ht_shared.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ library;
33

44
export 'src/exceptions/exceptions.dart';
55
export 'src/models/models.dart';
6+
export 'src/models/permission.dart';

lib/src/models/models.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
export 'auth_success_response.dart';
2-
export 'category.dart';
3-
export 'country.dart';
4-
export 'headline.dart';
5-
export 'paginated_reponse.dart';
6-
export 'response_metadata.dart';
7-
export 'source.dart';
8-
export 'success_api_response.dart';
1+
export 'news/news.dart';
2+
export 'permission.dart';
3+
export 'remote-config/remote_config.dart';
4+
export 'responses/responses.dart';
5+
export 'user-preferences/user_preferences.dart';
6+
export 'user-settings/user_settings.dart';
97
export 'user.dart';
8+
export 'user_role.dart';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/src/models/headline.dart renamed to lib/src/models/news/headline.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import 'package:equatable/equatable.dart';
2-
import 'package:ht_shared/src/models/category.dart';
3-
import 'package:ht_shared/src/models/source.dart';
2+
import 'package:ht_shared/src/models/news/news.dart';
43
import 'package:json_annotation/json_annotation.dart';
54
import 'package:meta/meta.dart';
65
import 'package:uuid/uuid.dart';
76

7+
export 'category.dart';
8+
export 'country.dart';
9+
export 'source.dart';
10+
811
part 'headline.g.dart';
912

1013
// Helper function for parsing DateTime, returning null on error
File renamed without changes.

0 commit comments

Comments
 (0)