From 757eea8f4749f0601901dd858499123aaf0f068f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 10 Dec 2017 23:03:08 +0100 Subject: [PATCH] DELETE api.module.admin (added delete) --- build/api/module/admin.php | 24 ++++++++++++++++++++---- build/database/repo/admin.php | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/build/api/module/admin.php b/build/api/module/admin.php index 0687fae..09265b0 100644 --- a/build/api/module/admin.php +++ b/build/api/module/admin.php @@ -50,7 +50,7 @@ * @mail Adresse mail de l'administrateur * @password Mot de passe de l'administrateur * - * @return id_admin UID de l'administrateur crée + * @return admin Données de l'administrateur crée * ---------------------------------------------------------*/ public static function post($args){ @@ -64,13 +64,13 @@ return [ 'error' => new Error(Err::RepoError) ]; /* (3) Renvoi @id_admin */ - return [ 'id_admin' => $id_created ]; + return [ 'id_admin' => Repo::request('admin', 'getById', $id_created) ]; } - /* (3) Updates an existing new administrator + /* (3) Updates an existing administrator * * @id_admin UID de l'administrateur * @mail [OPT] Adresse mail de l'administrateur @@ -81,7 +81,6 @@ ---------------------------------------------------------*/ public static function put($args){ extract($args); - debug(); /* (1) If @mail given ---------------------------------------------------------*/ @@ -114,4 +113,21 @@ } + + + /* (4) Deletes an existing administrator + * + * @id_admin UID de l'administrateur + * + * @return removed Whether the admin has been removed + * + ---------------------------------------------------------*/ + public static function delete($args){ + extract($args); + + /* (1) Dispatch du status */ + return [ 'removed' => Repo::request('admin', 'delete', $id_admin) ]; + + } + } diff --git a/build/database/repo/admin.php b/build/database/repo/admin.php index 9d3d2e1..3201c2b 100644 --- a/build/database/repo/admin.php +++ b/build/database/repo/admin.php @@ -278,6 +278,29 @@ } + /* (9) Deletes an admin + * + * @id_admin The admin UID + * + * @return removed Whether the admin has been removed or not + * + ---------------------------------------------------------*/ + public function delete(int $id_admin){ + + /* (1) Deletes the admin + ---------------------------------------------------------*/ + /* (1) Prepare Statement */ + $pst = $this->pdo->prepare("DELETE FROM `admin` WHERE `id_admin` = :id_admin"); + + /* (3) Bind variables */ + $pst->bindParam(':id_admin', $id_admin, \PDO::PARAM_INT); + + /* (4) Execute -> dispatch status */ + return $pst->execute(); + + } + + } \ No newline at end of file