From 2da458ad319682517490ca54d01035f21e1971d9 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 8 Dec 2017 03:39:29 +0100 Subject: [PATCH] FUCK YES -> api: POST message/emergency (now works with DB FINALLY) --- build/api/module/message.php | 15 +++++++++------ build/database/repo/emergency.php | 8 +++----- config/modules.json | 16 ++++++++-------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/build/api/module/message.php b/build/api/module/message.php index 09a4c7e..2100491 100644 --- a/build/api/module/message.php +++ b/build/api/module/message.php @@ -9,6 +9,9 @@ namespace api\module; +use \database\core\Repo; +use \error\core\Error; +use \error\core\Err; use kwebsocket\core\wsinterop; class message @@ -31,10 +34,10 @@ class message $id_user = null; $name = null; - if( count($_SESSSION['ADMIN']) > 0 ) + if( count($_SESSION['ADMIN']) > 0 ) $id_user = $_SESSION['ADMIN']['id']; - elseif( count($_SESSSION['USER']) > 0 ) + elseif( count($_SESSION['USER']) > 0 ) $id_user = $_SESSION['USER']['id']; else @@ -47,11 +50,11 @@ class message $id_created = Repo::request('emergency', 'create', $id_user, $name, - time(), $message, 0, $location[0], - is_null($URL_0) ? '' : $URL_0 + $location[1], + $URL_0 ); /* (2) If cannot create -> dispatch error */ @@ -73,14 +76,14 @@ class message 'location' => $location, 'id' => $id_created, 'channelType' => 'Emergency', - 'channelName' => is_null($URL_0) ? '' : $URL_0 + 'channelName' => $URL_0 ]); /* (3) Close socket */ $wsi->close(); - return ['sent' => true]; + return ['sent' => intval($id_created) ]; } public function DELETE_emergency($argv){ diff --git a/build/database/repo/emergency.php b/build/database/repo/emergency.php index 026ff62..4e8cd49 100644 --- a/build/database/repo/emergency.php +++ b/build/database/repo/emergency.php @@ -54,7 +54,6 @@ * * @id_user The user ID if defined * @name The user name (if not connected) - * @timestamp The timestamp * @message The message content * @type The message type * @latitude Sender latitude @@ -65,17 +64,16 @@ * FALSE on error * ---------------------------------------------------------*/ - public function create($id_user, String $name, int $timestamp, String $message, int $type, float $latitude, float $longitude, int $dep){ + public function create($id_user, String $name, String $message, int $type, float $latitude, float $longitude, $dep){ /* (2) Create the emergency ---------------------------------------------------------*/ /* (1) Prepare Statement */ $pst = $this->pdo->prepare("INSERT INTO `emergency`(`id_emergency`, `id_user`, `timestamp`, `name`, `message`, `type`, `latitude`, `longitude`, `dep`) - VALUES(DEFAULT, :id_user, :timestamp, :name, :message, :type, :latitude, :longitude, :dep)"); + VALUES(DEFAULT, :id_user, DEFAULT, :name, :message, :type, :latitude, :longitude, :dep)"); /* (3) Bind variables */ $pst->bindParam(':id_user', $id_user, \PDO::PARAM_INT); - $pst->bindParam(':timestamp', $timestamp, \PDO::PARAM_INT); $pst->bindParam(':name', $name, \PDO::PARAM_STR, 50); $pst->bindParam(':message', $message, \PDO::PARAM_STR); $pst->bindParam(':type', $type, \PDO::PARAM_INT); @@ -90,7 +88,7 @@ /* (2) Get the id ---------------------------------------------------------*/ /* (1) Get last inserted id */ - return $this->pdo->lastInsertId; + return $this->pdo->lastInsertId(); } diff --git a/config/modules.json b/config/modules.json index e776fa0..df06b29 100755 --- a/config/modules.json +++ b/config/modules.json @@ -98,26 +98,26 @@ "description" : "", "permissions": [], "parameters": { - "URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type" : "numeric", "optional" : true }, - "message": { "description": "message a publier", "type": "text" }, - "location": { "description": "coordonés GPS du message, des coordonnées invalide ne seront pas affiché", "type": "array" } + "URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type" : "numeric" }, + "message": { "description": "message a publier", "type": "text" }, + "location": { "description": "coordonés GPS du message, des coordonnées invalide ne seront pas affiché", "type": "array" } } }, "DELETE emergency": { "description": "", "permissions": [], "parameters": { - "URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type": "numeric", "optional": true }, - "id": { "description": "message a publier", "type": "text" } + "URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type": "numeric" }, + "id": { "description": "message a publier", "type": "text" } } }, "PUT emergency": { "description" : "", "permissions": [], "parameters": { - "URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type": "numeric", "optional" : true }, - "id": { "description": "message a publier", "type": "text" }, - "message": { "description": "message a publier", "type": "text" } + "URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type": "numeric" }, + "id": { "description": "message a publier", "type": "text" }, + "message": { "description": "message a publier", "type": "text" } } }, "GET emergency": {