Le commit un peu tardif de l'api
This commit is contained in:
79
api/index.php
Normal file
79
api/index.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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();
|
||||
|
||||
?>
|
Reference in New Issue
Block a user