GET api.module.admin (added get by id + get all)
This commit is contained in:
parent
13f4aba25d
commit
5cdc2f9945
|
@ -3,15 +3,41 @@
|
||||||
namespace api\module;
|
namespace api\module;
|
||||||
|
|
||||||
use \error\core\Error;
|
use \error\core\Error;
|
||||||
|
use \database\core\Repo;
|
||||||
|
|
||||||
|
|
||||||
class admin{
|
class admin{
|
||||||
|
|
||||||
|
|
||||||
public static function post($args){
|
/* (1) Return an admin data
|
||||||
|
*
|
||||||
|
* @id_admin<id> [OPT] UID de l'administrateur
|
||||||
|
*
|
||||||
|
* @return data<Array> Administrateurs correspondants
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
public static function get($args){
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
||||||
return [ 'admin' => 'post' ];
|
/* (1) If @id_admin is set -> get by id
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
if( is_numeric($id_admin) ){
|
||||||
|
|
||||||
|
/* (1) Search admin by id */
|
||||||
|
$fetch_admin = Repo::request('admin', 'getById', $id_admin);
|
||||||
|
|
||||||
|
/* (2) If not found -> return empty data */
|
||||||
|
if( !$fetch_admin )
|
||||||
|
return [ 'data' => [] ];
|
||||||
|
|
||||||
|
/* (3) Return fetched admin */
|
||||||
|
return [ 'data' => [$fetch_admin] ];
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Else -> get all
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
}else
|
||||||
|
return [ 'data' => Repo::request('admin', 'getAll') ];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
public function getAll(){
|
public function getAll(){
|
||||||
|
|
||||||
/* (1) Statement */
|
/* (1) Statement */
|
||||||
$st = $this->pdo->query("SELECT * FROM `admin` ORDER BY `username` ASC");
|
$st = $this->pdo->query("SELECT `id_admin`, `username`, `mail` FROM `admin` ORDER BY `username` ASC");
|
||||||
|
|
||||||
/* (2) Fetched data */
|
/* (2) Fetched data */
|
||||||
return $st->fetchAll();
|
return $st->fetchAll();
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
public function getById(int $id_admin){
|
public function getById(int $id_admin){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `id_admin` = :id_admin LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `id_admin` = :id_admin LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':id_admin', $id_admin, \PDO::PARAM_INT);
|
$pst->bindParam(':id_admin', $id_admin, \PDO::PARAM_INT);
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
public function getByMail(String $mail){
|
public function getByMail(String $mail){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `mail` = :mail LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `mail` = :mail LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':mail', $mail, \PDO::PARAM_STR, 50);
|
$pst->bindParam(':mail', $mail, \PDO::PARAM_STR, 50);
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
public function getByUsername(String $username){
|
public function getByUsername(String $username){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `username` = :username LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `username` = :username LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':username', $username, \PDO::PARAM_STR, 20);
|
$pst->bindParam(':username', $username, \PDO::PARAM_STR, 20);
|
||||||
|
@ -109,7 +109,7 @@
|
||||||
public function getByToken(String $token){
|
public function getByToken(String $token){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `token` is not NULL AND `token` = :token LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `token` is not NULL AND `token` = :token LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':token', $token, \PDO::PARAM_STR, 128);
|
$pst->bindParam(':token', $token, \PDO::PARAM_STR, 128);
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"GET": {
|
"GET": {
|
||||||
"description": "Deletes an administrator",
|
"description": "Gets an administrator | Gets all administrators if no id defined",
|
||||||
"permissions": [["admin"]],
|
"permissions": [["admin"]],
|
||||||
"parameters": {}
|
"parameters": {
|
||||||
|
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "optional": true, "rename": "id_admin" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue