summaryrefslogtreecommitdiff
path: root/player-android/lib/api/dio_player_api_client.dart
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-21 22:54:27 +0300
committerPaul Buetow <paul@buetow.org>2026-05-21 22:54:27 +0300
commit444fb60ccacf7cba02467f7d6af2efd5d44e3b3b (patch)
tree5f2b451b11b653071f1bcc35f0a197b1068ae575 /player-android/lib/api/dio_player_api_client.dart
parentd9887828685db241e01436e99885056eb61f06c1 (diff)
Implement NotesEditorScreen with auto-save debounce and clear confirmation (6b)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'player-android/lib/api/dio_player_api_client.dart')
-rw-r--r--player-android/lib/api/dio_player_api_client.dart43
1 files changed, 43 insertions, 0 deletions
diff --git a/player-android/lib/api/dio_player_api_client.dart b/player-android/lib/api/dio_player_api_client.dart
index 0b76b60..fdf16d1 100644
--- a/player-android/lib/api/dio_player_api_client.dart
+++ b/player-android/lib/api/dio_player_api_client.dart
@@ -474,6 +474,49 @@ class DioPlayerApiClient extends PlayerApiClient {
}
// ---------------------------------------------------------------------------
+ // Notes
+ // ---------------------------------------------------------------------------
+
+ /// Returns the authenticated user's note for [mediaId], or `null` if none.
+ ///
+ /// GET /api/v1/media/{id}/notes
+ /// The server responds with 200 + a Note JSON object when a note exists, or
+ /// 204 No Content when there is no note. Dio raises no exception on 204, so
+ /// we detect the empty body and return null rather than trying to decode it.
+ @override
+ Future<Note?> getNote(int mediaId) async {
+ final response = await rawDio.get<dynamic>(
+ '$_kApiV1/media/$mediaId/notes',
+ );
+ // 204 No Content — the server signals "no note exists" with an empty body.
+ if (response.statusCode == 204 || response.data == null) return null;
+ final data = response.data;
+ if (data is Map<String, dynamic>) return Note.fromJson(data);
+ return null;
+ }
+
+ /// Creates or updates the authenticated user's note for [mediaId].
+ ///
+ /// POST /api/v1/media/{id}/notes body: {"content": "<text>"}
+ /// Returns the saved [Note] on success.
+ @override
+ Future<Note> upsertNote(int mediaId, String content) async {
+ final response = await rawDio.post<Map<String, dynamic>>(
+ '$_kApiV1/media/$mediaId/notes',
+ data: {'content': content},
+ );
+ return Note.fromJson(response.data!);
+ }
+
+ /// Deletes the authenticated user's note for [mediaId].
+ ///
+ /// DELETE /api/v1/media/{id}/notes — returns 200 {"status": "ok"}.
+ @override
+ Future<void> deleteNote(int mediaId) async {
+ await rawDio.delete<void>('$_kApiV1/media/$mediaId/notes');
+ }
+
+ // ---------------------------------------------------------------------------
// Private helpers
// ---------------------------------------------------------------------------