|
|
|
@ -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(); |
|
|
|
|