diff --git a/api/post/create.php b/api/post/create.php
index 0b7a5b4..bf0b44a 100644
--- a/api/post/create.php
+++ b/api/post/create.php
@@ -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()]);
}
?>
\ No newline at end of file
diff --git a/api/post/find.php b/api/post/find.php
index 4adcd43..4581b3f 100644
--- a/api/post/find.php
+++ b/api/post/find.php
@@ -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");
diff --git a/api/post/index.php b/api/post/index.php
index 9621bce..0474fc9 100644
--- a/api/post/index.php
+++ b/api/post/index.php
@@ -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);
}
diff --git a/docs/SERVER CONFIGURATION.md b/docs/SERVER CONFIGURATION.md
index 073a85d..1342a06 100644
--- a/docs/SERVER CONFIGURATION.md
+++ b/docs/SERVER CONFIGURATION.md
@@ -3,4 +3,4 @@
Restrict access to files:
- Any file from `api` directory with prepended `_`
-- `config.json`
\ No newline at end of file
+- `config.json`
diff --git a/front/pages/new_post/page.php b/front/pages/new_post/page.php
index 2870f13..50eb4ae 100644
--- a/front/pages/new_post/page.php
+++ b/front/pages/new_post/page.php
@@ -26,10 +26,10 @@ if (isset($_POST) && $_POST) {
$result = Post_Create_Method($_POST, $_FILES);
if ($result->IsError()) { // Something happened
NTFY_AddNotice("Failed to create post! Reason:
" . $result->GetError());
- } /*else { // All OK
- header("Location: .");
+ } else { // All OK
+ header("Location: ./?do=view_post&id=" + strval($result->GetData()));
exit();
- } TODO: redirect to page with new post */
+ }
} else {
NTFY_AddNotice("You must supply image and tags for post");
}
diff --git a/front/pages/search_posts/page.php b/front/pages/search_posts/page.php
index 1fc1bf8..066a407 100644
--- a/front/pages/search_posts/page.php
+++ b/front/pages/search_posts/page.php
@@ -174,7 +174,6 @@ NTFY_EchoAllNotices();
} else {
echo "
Can't fetch comments
\n"; + } else { + $commentsList = $reqResult->GetData(); + $commentsAmount = count($commentsList); + echo "Comments: " . strval($commentsAmount) . "
\n"; + foreach ($commentsList as $commentData) { // TODO + echo "\n"; + echo strval($commentData["created_at"]) . "
\n"; + echo "\n"; //"04/04/2024 04:20
\n"; + echo "Guy\n"; + echo "
cool story bob
\n"; + echo "