Начал делать API для постов

This commit is contained in:
2023-09-06 05:38:18 +03:00
parent 983a5d0353
commit 9a4658f3ea
7 changed files with 71 additions and 1 deletions

View File

@@ -5,6 +5,21 @@ require_once("../_utils.php");
// Increment number of views for post
function Post_AddView ($id) {
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();
if (!(bool)$d) {
require_once("../_json.php");
ReturnJSONError($Err_Int_Unexpected, "failed to increment number of views");
}
}
// Get single publication by ID
function Post_GetByID ($id) {
global $db;
@@ -34,7 +49,7 @@ function Post_GetByID ($id) {
$result["preview_path"] = $d["preview_path"];
$result["edit_lock"] = $d["edit_lock"];
// TODO: increment views of post
Post_AddView($id);
return $result;
}