Начат запил страницы отображающей пост

This commit is contained in:
2024-04-27 20:47:41 +03:00
parent 62b7b68976
commit e538a76b09
9 changed files with 237 additions and 17 deletions

View File

@@ -186,7 +186,7 @@ function Post_Create (
if ($s->execute() === false)
return new ReturnT(err_code: E_DBE_INSERTFAIL, err_desc: "failed to create post record in DB");
$result = true;
$result = $db->insert_id;
return new ReturnT(data: $result);
}
@@ -199,10 +199,12 @@ function Post_Create (
* METHOD
* Create single publication
* Request fields:
* tags - list of tags, should be delimited by comma
* tags - list of tags, should be delimited by comma
* title - optional title for post
* Files fields:
* pic - id of file object in $_FILES variable
* pic - id of file object in $_FILES variable
* Return value:
* id - unique identifier of created post
*/
function Post_Create_Method (array $req, array $files): ReturnT {
global $Config, $LOGGED_IN, $THIS_USER;
@@ -341,7 +343,7 @@ if (Utils_ThisFileIsRequested(__FILE__)) {
if ($result->IsError())
$result->ThrowJSONError();
else
JSON_ReturnData(["success" => $result->GetData()]);
JSON_ReturnData(["id" => $result->GetData()]);
}
?>

View File

@@ -5,6 +5,7 @@
// Includes
if (isset($IS_FRONTEND) && $IS_FRONTEND) {
require_once("api/_config.php");
require_once("api/_auth.php");
require_once("api/_utils.php");
require_once("api/_input_checks.php");
@@ -13,6 +14,7 @@ if (isset($IS_FRONTEND) && $IS_FRONTEND) {
require_once("api/user/index.php");
require_once("api/post/index.php");
} else {
require_once("../_config.php");
require_once("../_auth.php");
require_once("../_utils.php");
require_once("../_input_checks.php");

View File

@@ -41,12 +41,10 @@ function Post_AddView (int $id): ReturnT {
global $db;
$s = $db->prepare("UPDATE posts SET views = views + 1 WHERE id = ?");
$s->bind_param("s", $id);
$s->execute();
$d = $s->get_result()->fetch_assoc();
$s->bind_param("i", $id);
if (!(bool)$d)
return new ReturnT(err_code: E_UIN_WRONGID, err_desc: "failed to increment number of views");
if (!$s->execute())
return new ReturnT(err_code: E_DBE_UNKNOWN, err_desc: "failed to execute statement");
return new ReturnT(data: true);
}