From 444fb60ccacf7cba02467f7d6af2efd5d44e3b3b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 21 May 2026 22:54:27 +0300 Subject: Implement NotesEditorScreen with auto-save debounce and clear confirmation (6b) Co-Authored-By: Claude Sonnet 4.6 --- player-android/lib/api/dio_player_api_client.dart | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'player-android/lib/api/dio_player_api_client.dart') 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 @@ -473,6 +473,49 @@ class DioPlayerApiClient extends PlayerApiClient { return PodcastFeed.fromJson(response.data!); } + // --------------------------------------------------------------------------- + // 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 getNote(int mediaId) async { + final response = await rawDio.get( + '$_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) return Note.fromJson(data); + return null; + } + + /// Creates or updates the authenticated user's note for [mediaId]. + /// + /// POST /api/v1/media/{id}/notes body: {"content": ""} + /// Returns the saved [Note] on success. + @override + Future upsertNote(int mediaId, String content) async { + final response = await rawDio.post>( + '$_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 deleteNote(int mediaId) async { + await rawDio.delete('$_kApiV1/media/$mediaId/notes'); + } + // --------------------------------------------------------------------------- // Private helpers // --------------------------------------------------------------------------- -- cgit v1.2.3