query->title ?? false; if ($id === null) { if($title) { $res = MusicAPI::findAllSongByTitleContaining($title); } else { $res = MusicAPI::findAllSong(); } Flight::json(["results" => $res]); } else { $res = MusicAPI::findSongById($id); if ($res) { Flight::json($res); } else { Flight::halt(404); } } } function findAlbum($id = null) { $name = Flight::request()->query->name ?? false; if ($id === null) { if ($name){ $res = MusicAPI::findAlbumByNameContaining($name); } else { $res = MusicAPI::findAllAlbum(); } Flight::json(["results" => $res]); } else { $res = MusicAPI::findAlbumById($id); if ($res) { Flight::json($res); } else { Flight::halt(404); } } } function findArtist($id = null) { $name = Flight::request()->query->name ?? false; if ($id === null) { if ($name){ $res = MusicAPI::findArtsistByNameContaining($name); } else { $res = MusicAPI::findAllArtist(); } Flight::json(["results" => $res]); } else { $res = MusicAPI::findArtsistById($id); if ($res) { Flight::json($res); } else { Flight::halt(404); } } } 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(); ?>