You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.9 KiB
104 lines
2.9 KiB
|
|
export async function createPlaylist(body, token, addAlert) {
|
|
try {
|
|
const response = await fetch(`https://localhost/api/playlists`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${token}`
|
|
},
|
|
body: JSON.stringify(body)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to create playlist');
|
|
}
|
|
|
|
const data = await response.json();
|
|
addAlert('success', 'Playlist created successfully');
|
|
return data;
|
|
} catch (error) {
|
|
addAlert('error', error.message);
|
|
}
|
|
}
|
|
|
|
export async function addToPlaylist(id, body, token, addAlert) {
|
|
try {
|
|
const response = await fetch(`https://localhost/api/playlists/${id}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${token}`
|
|
},
|
|
body: JSON.stringify(body)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to add video to playlist');
|
|
}
|
|
|
|
const data = await response.json();
|
|
addAlert('success', 'Vidéo ajoutée à la playlist avec succès');
|
|
return data;
|
|
} catch (error) {
|
|
addAlert('error', "Erreur lors de l'ajout à la playlist");
|
|
}
|
|
|
|
}
|
|
|
|
export async function getPlaylistById(id, token, addAlert) {
|
|
try {
|
|
const response = await fetch(`https://localhost/api/playlists/${id}`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch playlist');
|
|
}
|
|
|
|
const data = await response.json();
|
|
return data;
|
|
} catch (error) {
|
|
addAlert('error', error.message);
|
|
}
|
|
}
|
|
|
|
export async function deletePlaylist(id, token, addAlert) {
|
|
try {
|
|
const response = await fetch(`https://localhost/api/playlists/${id}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to delete playlist');
|
|
}
|
|
|
|
addAlert('success', 'Playlist deleted successfully');
|
|
} catch (error) {
|
|
addAlert('error', error.message);
|
|
}
|
|
}
|
|
|
|
export async function deleteVideo(playlistId, videoId, token, addAlert) {
|
|
try {
|
|
const response = await fetch(`https://localhost/api/playlists/${playlistId}/video/${videoId}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to delete video');
|
|
}
|
|
|
|
addAlert('success', 'Video deleted successfully');
|
|
} catch (error) {
|
|
addAlert('error', error.message);
|
|
}
|
|
}
|
|
|