diff --git a/backend/app/controllers/playlist.controller.js b/backend/app/controllers/playlist.controller.js index ace7ba7..c85186a 100644 --- a/backend/app/controllers/playlist.controller.js +++ b/backend/app/controllers/playlist.controller.js @@ -238,26 +238,29 @@ export async function getSeeLater(req, res) { const client = await getClient(); const query = ` SELECT - JSON_AGG( - json_build_object( - 'video_id', videos.id, - 'title', videos.title, - 'thumbnail', videos.thumbnail, - 'video_decscription', videos.description, - 'channel', videos.channel, - 'visibility', videos.visibility, - 'file', videos.file, - 'format', videos.format, - 'release_date', videos.release_date, - 'channel_id', channels.id, - 'owner', channels.owner, - 'views', COALESCE(video_views.view_count, 0), - 'creator', json_build_object( - 'name', channels.name, - 'profilePicture', users.picture, - 'description', channels.description + COALESCE( + JSON_AGG( + json_build_object( + 'video_id', videos.id, + 'title', videos.title, + 'thumbnail', videos.thumbnail, + 'video_decscription', videos.description, + 'channel', videos.channel, + 'visibility', videos.visibility, + 'file', videos.file, + 'format', videos.format, + 'release_date', videos.release_date, + 'channel_id', channels.id, + 'owner', channels.owner, + 'views', COALESCE(video_views.view_count, 0), + 'creator', json_build_object( + 'name', channels.name, + 'profilePicture', users.picture, + 'description', channels.description + ) ) - ) + ) FILTER (WHERE videos.id IS NOT NULL), + '[]'::json ) AS videos FROM public.playlists @@ -285,14 +288,14 @@ export async function getSeeLater(req, res) { try { const result = await client.query(query, [userId]); if (result.rows.length === 0) { - logger.write("No 'See Later' playlist found for user with id " + userId, 404); + logger.write("No 'See Later' playlist found for user with id " + userId, 200); client.release(); - res.status(404).json({ error: "'See Later' playlist not found" }); + res.status(200).json([]); return; } logger.write("'See Later' playlist retrieved for user with id " + userId, 200); client.release(); - res.status(200).json(result.rows[0].videos); + res.status(200).json(result.rows[0].videos || []); } catch (error) { logger.write("Error retrieving 'See Later' playlist: " + error.message, 500); client.release(); diff --git a/backend/logs/access.log b/backend/logs/access.log index 552e604..fd02723 100644 --- a/backend/logs/access.log +++ b/backend/logs/access.log @@ -11461,3 +11461,26 @@ [2025-08-31 10:29:58.869] [undefined] GET(/:id/stats): try to get stats [2025-08-31 10:29:58.875] [undefined] GET(/:id): Successfully get channel with id 1 with status 200 [2025-08-31 10:29:58.885] [undefined] GET(/:id/stats): Successfully get stats with status 200 +[2025-08-31 10:30:58.389] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-03 17:34:12.979] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-03 17:34:15.647] [undefined] GET(/:id): failed due to invalid values with status 400 +[2025-09-03 17:34:15.660] [undefined] GET(/:id/similar): failed due to invalid values with status 400 +[2025-09-03 17:34:15.671] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-09-03 17:34:15.736] [undefined] GET(/:id/views): failed due to invalid values with status 400 +[2025-09-03 17:34:24.176] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-03 17:34:26.470] [undefined] GET(/:id): failed due to invalid values with status 400 +[2025-09-03 17:34:26.478] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-09-03 17:34:26.485] [undefined] GET(/:id/similar): failed due to invalid values with status 400 +[2025-09-03 17:34:26.494] [undefined] GET(/:id/views): failed due to invalid values with status 400 +[2025-09-03 17:34:26.941] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-03 17:34:29.468] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-09-03 17:34:29.523] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-09-03 17:34:29.535] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-09-03 17:34:29.541] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-09-03 17:34:29.550] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-09-03 17:34:30.404] [undefined] GET(/:id): Playlist retrieved with id 1 with status 200 +[2025-09-03 17:34:31.607] [undefined] DELETE(/:id/video/:videoId): Video deleted from playlist with id 1 with status 200 +[2025-09-03 17:34:31.690] [undefined] GET(/:id): Playlist retrieved with id 1 with status 200 +[2025-09-03 17:34:32.741] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-03 17:34:41.091] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-03 17:35:57.790] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200