mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
The list endpoints now return a total count alongside the page so the
front-end can show how many pages exist and offer a last-page jump.
Backend: add count(is_new) and count_devices(...) (sharing a WHERE-builder
with list_devices so page and count can't drift), wrap both list responses
in {items, total_count} structs, and register them with utoipa.
Front-end: parse the wrapper shape (dropping the fetch-one-extra trick),
add a Last-page button and a responsive "Page X of Y" / "X / Y" label to
the shared PaginationBar, and track the total in both lists. Notifications
re-sync the count on every fetch and decrement it locally on mark-read/
unread removals so the count stays accurate without a re-fetch.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1001 B
Dart
39 lines
1001 B
Dart
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, int totalCount})> 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,
|
|
},
|
|
cancelToken: cancelToken,
|
|
);
|
|
|
|
return _paginate(
|
|
response.data as Map<String, dynamic>,
|
|
(item) => Notification.fromJson(item),
|
|
);
|
|
}
|
|
}
|