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;
|
namespace api\module;
|
||||||
|
|
||||||
|
|
||||||
|
use \database\core\Repo;
|
||||||
|
use \error\core\Error;
|
||||||
|
use \error\core\Err;
|
||||||
use kwebsocket\core\wsinterop;
|
use kwebsocket\core\wsinterop;
|
||||||
|
|
||||||
class message
|
class message
|
||||||
|
@ -31,10 +34,10 @@ class message
|
||||||
$id_user = null;
|
$id_user = null;
|
||||||
$name = null;
|
$name = null;
|
||||||
|
|
||||||
if( count($_SESSSION['ADMIN']) > 0 )
|
if( count($_SESSION['ADMIN']) > 0 )
|
||||||
$id_user = $_SESSION['ADMIN']['id'];
|
$id_user = $_SESSION['ADMIN']['id'];
|
||||||
|
|
||||||
elseif( count($_SESSSION['USER']) > 0 )
|
elseif( count($_SESSION['USER']) > 0 )
|
||||||
$id_user = $_SESSION['USER']['id'];
|
$id_user = $_SESSION['USER']['id'];
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -47,11 +50,11 @@ class message
|
||||||
$id_created = Repo::request('emergency', 'create',
|
$id_created = Repo::request('emergency', 'create',
|
||||||
$id_user,
|
$id_user,
|
||||||
$name,
|
$name,
|
||||||
time(),
|
|
||||||
$message,
|
$message,
|
||||||
0,
|
0,
|
||||||
$location[0],
|
$location[0],
|
||||||
is_null($URL_0) ? '' : $URL_0
|
$location[1],
|
||||||
|
$URL_0
|
||||||
);
|
);
|
||||||
|
|
||||||
/* (2) If cannot create -> dispatch error */
|
/* (2) If cannot create -> dispatch error */
|
||||||
|
@ -73,14 +76,14 @@ class message
|
||||||
'location' => $location,
|
'location' => $location,
|
||||||
'id' => $id_created,
|
'id' => $id_created,
|
||||||
'channelType' => 'Emergency',
|
'channelType' => 'Emergency',
|
||||||
'channelName' => is_null($URL_0) ? '' : $URL_0
|
'channelName' => $URL_0
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/* (3) Close socket */
|
/* (3) Close socket */
|
||||||
$wsi->close();
|
$wsi->close();
|
||||||
|
|
||||||
|
|
||||||
return ['sent' => true];
|
return ['sent' => intval($id_created) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DELETE_emergency($argv){
|
public function DELETE_emergency($argv){
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
*
|
*
|
||||||
* @id_user<int|null> The user ID if defined
|
* @id_user<int|null> The user ID if defined
|
||||||
* @name<String> The user name (if not connected)
|
* @name<String> The user name (if not connected)
|
||||||
* @timestamp<int> The timestamp
|
|
||||||
* @message<String> The message content
|
* @message<String> The message content
|
||||||
* @type<int> The message type
|
* @type<int> The message type
|
||||||
* @latitude<int> Sender latitude
|
* @latitude<int> Sender latitude
|
||||||
|
@ -65,17 +64,16 @@
|
||||||
* FALSE on error
|
* 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
|
/* (2) Create the emergency
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("INSERT INTO `emergency`(`id_emergency`, `id_user`, `timestamp`, `name`, `message`, `type`, `latitude`, `longitude`, `dep`)
|
$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 */
|
/* (3) Bind variables */
|
||||||
$pst->bindParam(':id_user', $id_user, \PDO::PARAM_INT);
|
$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(':name', $name, \PDO::PARAM_STR, 50);
|
||||||
$pst->bindParam(':message', $message, \PDO::PARAM_STR);
|
$pst->bindParam(':message', $message, \PDO::PARAM_STR);
|
||||||
$pst->bindParam(':type', $type, \PDO::PARAM_INT);
|
$pst->bindParam(':type', $type, \PDO::PARAM_INT);
|
||||||
|
@ -90,7 +88,7 @@
|
||||||
/* (2) Get the id
|
/* (2) Get the id
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Get last inserted id */
|
/* (1) Get last inserted id */
|
||||||
return $this->pdo->lastInsertId;
|
return $this->pdo->lastInsertId();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type" : "numeric", "optional" : true },
|
"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" },
|
"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>" }
|
"location": { "description": "coordonés GPS du message, des coordonnées invalide ne seront pas affiché", "type": "array<numeric>" }
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type": "numeric", "optional": true },
|
"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" }
|
"id": { "description": "message a publier", "type": "text" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -115,7 +115,7 @@
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"URL_0": { "description": "code departement, si le paramètre n'est pas fourni le message est envoyé en broadcast", "type": "numeric", "optional" : true },
|
"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" },
|
"id": { "description": "message a publier", "type": "text" },
|
||||||
"message": { "description": "message a publier", "type": "text" }
|
"message": { "description": "message a publier", "type": "text" }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue