Skip to content

Commit ed619e9

Browse files
committed
docs(data): clarify generic data endpoint usage
- Emphasize /data/[id] route preference - Clarify user scoping for user data - Explain AppConfig single instance access
1 parent 353b160 commit ed619e9

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

lib/src/registry/model_registry.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
200200
requiresOwnershipCheck: true, // Must be the owner
201201
),
202202
postPermission: const ModelActionPermission(
203-
type: RequiredPermissionType.unsupported, // User creation handled by auth routes
203+
type: RequiredPermissionType
204+
.unsupported, // User creation handled by auth routes
204205
),
205206
putPermission: const ModelActionPermission(
206207
type: RequiredPermissionType.specificPermission,

routes/api/v1/data/index.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ Future<Response> _handleGet(
146146
startAfterId: startAfterId,
147147
limit: limit,
148148
);
149-
case 'user': // Handle User model specifically if needed, or rely on generic
149+
case 'user':
150150
final repo = context.read<HtDataRepository<User>>();
151-
// Note: readAll/readAllByQuery on User repo might need special handling
152-
// depending on whether non-admins can list *all* users or just their own.
153-
// Assuming for now readAll/readAllByQuery with userId scopes to owned.
151+
// Note: While readAll/readAllByQuery is used here for consistency
152+
// with the generic endpoint, fetching a specific user by ID via
153+
// the /data/[id] route is the semantically preferred method.
154+
// The userIdForRepoCall ensures scoping to the authenticated user
155+
// if the repository supports it.
154156
paginatedResponse = specificQuery.isNotEmpty
155157
? await repo.readAllByQuery(
156158
specificQuery,
@@ -163,8 +165,12 @@ Future<Response> _handleGet(
163165
startAfterId: startAfterId,
164166
limit: limit,
165167
);
166-
case 'user_app_settings': // New case for UserAppSettings
168+
case 'user_app_settings':
167169
final repo = context.read<HtDataRepository<UserAppSettings>>();
170+
// Note: While readAll/readAllByQuery is used here for consistency
171+
// with the generic endpoint, fetching the user's settings by ID
172+
// via the /data/[id] route is the semantically preferred method
173+
// for this single-instance, user-owned model.
168174
paginatedResponse = specificQuery.isNotEmpty
169175
? await repo.readAllByQuery(
170176
specificQuery,
@@ -177,8 +183,12 @@ Future<Response> _handleGet(
177183
startAfterId: startAfterId,
178184
limit: limit,
179185
);
180-
case 'user_content_preferences': // New case for UserContentPreferences
186+
case 'user_content_preferences':
181187
final repo = context.read<HtDataRepository<UserContentPreferences>>();
188+
// Note: While readAll/readAllByQuery is used here for consistency
189+
// with the generic endpoint, fetching the user's preferences by ID
190+
// via the /data/[id] route is the semantically preferred method
191+
// for this single-instance, user-owned model.
182192
paginatedResponse = specificQuery.isNotEmpty
183193
? await repo.readAllByQuery(
184194
specificQuery,
@@ -191,8 +201,12 @@ Future<Response> _handleGet(
191201
startAfterId: startAfterId,
192202
limit: limit,
193203
);
194-
case 'app_config': // New case for AppConfig (read by admin)
204+
case 'app_config':
195205
final repo = context.read<HtDataRepository<AppConfig>>();
206+
// Note: While readAll/readAllByQuery is used here for consistency
207+
// with the generic endpoint, fetching the single AppConfig instance
208+
// by its fixed ID ('app_config') via the /data/[id] route is the
209+
// semantically preferred method for this global singleton model.
196210
paginatedResponse = specificQuery.isNotEmpty
197211
? await repo.readAllByQuery(
198212
specificQuery,

0 commit comments

Comments
 (0)