mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Split oott_api.dart into per-domain modules
Break the 372-line frontend API client into focused files under lib/utils/api/: error mapping (api_error.dart), Dio setup behind a buildDio factory (dio_config.dart), and device/scanner/notification endpoints as extensions in part files. Collapse the five near-identical scanner-status methods via a generic _getModel helper and de-duplicate the pagination logic via a shared _paginate helper. The BackendAPI singleton and dioErrorToUserMessage remain importable from oott_api.dart unchanged, so no call sites are affected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5f7a1287a1
commit
c9e79e028f
@@ -0,0 +1,39 @@
|
||||
part of '../oott_api.dart';
|
||||
|
||||
/// Notification endpoints: listing and read/new state transitions.
|
||||
extension NotificationApi on BackendAPI {
|
||||
Future<void> markNotificationAsRead(int id) async {
|
||||
await _dio.get('/notifications/$id');
|
||||
}
|
||||
|
||||
Future<void> markNotificationAsNew(int id) async {
|
||||
await _dio.post('/notifications/$id/mark_as_new');
|
||||
}
|
||||
|
||||
Future<void> markAllNotificationsAsRead() async {
|
||||
await _dio.post('/notifications/mark_all_as_old');
|
||||
}
|
||||
|
||||
Future<({List<Notification> items, bool hasNextPage})> listNotifications(
|
||||
bool? isNew, {
|
||||
int page = 0,
|
||||
int perPage = 5,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
final response = await _dio.get(
|
||||
'/notifications',
|
||||
queryParameters: {
|
||||
'is_new': isNew ?? '',
|
||||
'page_offset': page * perPage,
|
||||
'page_limit': perPage + 1,
|
||||
},
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
return _paginate(
|
||||
response.data as List<dynamic>,
|
||||
(item) => Notification.fromJson(item),
|
||||
perPage,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user