Debut gestion playlist dans api + creation playlist front

This commit is contained in:
2024-06-27 19:40:54 +02:00
parent 35a6e4266f
commit 286e660f63
5 changed files with 261 additions and 20 deletions

41
api/index.php Normal file → Executable file
View File

@@ -8,6 +8,9 @@ MusicAPI::init();
Flight::route('GET /songs(/@id)', 'findSong');
Flight::route('GET /albums(/@id)', 'findAlbum');
Flight::route('GET /artists(/@id)', 'findArtist');
Flight::route('GET /playlists(/@id)', 'findPlaylist');
Flight::route('POST /playlists', 'createPlaylist');
Flight::route('DELETE /playlists/@id', 'deletePlaylist');
function findSong($id = null)
{
@@ -74,6 +77,44 @@ function findArtist($id = null)
}
}
function findPlaylist($id = null)
{
if ($id === null) {
$res = MusicAPI::findAllPlaylists();
Flight::json(["results" => $res]);
} else {
$res = MusicAPI::findPlaylistById($id);
if ($res) {
Flight::json($res);
} else {
Flight::halt(404);
}
}
}
function createPlaylist()
{
$data = Flight::request()->data;
$name = $data->name ?? null;
if ($name) {
$id = MusicAPI::createPlaylist($name);
Flight::json(["id" => $id], 201);
} else {
Flight::halt(400, "Missing name parameter");
}
}
function deletePlaylist($id)
{
$res = MusicAPI::deletePlaylist($id);
if ($res) {
Flight::json(["status" => "success"]);
} else {
Flight::halt(404);
}
}
Flight::start();
?>