SAE_RIOT_2024/api/index.php
2024-06-27 10:07:19 +02:00

80 lines
1.5 KiB
PHP

<?php
require 'flight/Flight.php';
require 'model/model.php';
MusicAPI::init();
Flight::route('GET /songs(/@id)', 'findSong');
Flight::route('GET /albums(/@id)', 'findAlbum');
Flight::route('GET /artists(/@id)', 'findArtist');
function findSong($id = null)
{
$title = Flight::request()->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);
}
}
}
Flight::start();
?>