FUCK YES -> api: POST message/emergency (now works with DB FINALLY)
This commit is contained in:
parent
8e78142119
commit
2da458ad31
|
@ -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){
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
*
|
||||
* @id_user<int|null> The user ID if defined
|
||||
* @name<String> The user name (if not connected)
|
||||
* @timestamp<int> The timestamp
|
||||
* @message<String> The message content
|
||||
* @type<int> The message type
|
||||
* @latitude<int> 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();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<numeric>" }
|
||||
"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<numeric>" }
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
|
|
Loading…
Reference in New Issue