Debut gestion playlist dans api + creation playlist front
This commit is contained in:
41
api/index.php
Normal file → Executable file
41
api/index.php
Normal file → Executable 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();
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user