diff --git a/TODO.md b/TODO.md index c925f25..742785b 100644 --- a/TODO.md +++ b/TODO.md @@ -14,9 +14,9 @@ - Бэк - Аккаунты - Регистрация нового - - Ник - - Мыло - - Пароль + - ~~Ник~~ + - ~~Мыло~~ + - ~~Пароль~~ - Айди приглашения - Роли - Новичок diff --git a/api/post/index.php b/api/post/index.php new file mode 100644 index 0000000..e882142 --- /dev/null +++ b/api/post/index.php @@ -0,0 +1,64 @@ +prepare("SELECT * FROM posts WHERE id = ?"); + $s->bind_param("s", $id); + $s->execute(); + $d = $s->get_result()->fetch_assoc(); + + if (!(bool)$d) { + return null; + } + + $result["id"] = $d["id"]; + $result["author_id"] = $d["author_id"]; + if ($d["comments_enabled"]) + $result["comment_section_id"] = $d["comment_section_id"]; + $result["created_at"] = $d["created_at"]; + $result["tags"] = $d["tags"]; + $result["title"] = $d["title"]; + $result["votes_up"] = $d["votes_up"]; + $result["votes_down"] = $d["votes_down"]; + $result["views"] = $d["views"] + 1; + $result["pic_path"] = $d["pic_path"]; + $result["preview_path"] = $d["preview_path"]; + $result["edit_lock"] = $d["edit_lock"]; + + // TODO: increment views of post + + return $result; +} + + + +if (ThisFileIsRequested(__FILE__)) { + require_once("../_json.php"); + + if (isset($_REQUEST["id"])) { + if (!ctype_digit($_REQUEST["id"])) + ReturnJSONError($Err_RDP_InvalidID, "id must be numeric"); + $UserID = intval($_REQUEST["id"]); + } else { + ReturnJSONError($Err_RDP_InvalidID, "id must be specified"); + } + + // TODO: check permissions + + $ResponseData = Post_GetByID($_REQUEST["id"]); + if ($ResponseData) + ReturnJSONData($ResponseData); + else + ReturnJSONError($Err_DP_IDNotFound, "wrong id"); +} + +?> \ No newline at end of file diff --git a/docs/API.md b/docs/API.md index caca91d..184d3f4 100644 --- a/docs/API.md +++ b/docs/API.md @@ -19,26 +19,26 @@ Files starting from "_" ("_example.php") are intended for internal use only. - _errors.php: error strings - _json.php: wrappers for JSON functions -- stats.php (GET/POST): all general statistics about this instance +- [ ] stats.php (GET/POST): all general statistics about this instance -- admin/ (POST): private statistics about this instance -- admin/dbview.php (POST): manage databases -- admin/nukelock.php (POST): emergency "red button" to lock all operations to read-only mode +- [ ] admin/ (POST): private statistics about this instance +- [ ] admin/dbview.php (POST): manage databases +- [ ] admin/nukelock.php (POST): emergency "red button" to lock all operations to read-only mode -- user/ (GET/POST): get user information by id -- user/list.php (GET/POST): get list of all users -- user/create.php (POST): create new user account -- user/edit.php (POST): edit user profile -- user/delete.php (POST): delete user account +- [x] user/ (GET/POST): get user information by id +- [ ] user/list.php (GET/POST): get list of all users +- [ ] user/create.php (POST): create new user account +- [ ] user/edit.php (POST): edit user profile +- [ ] user/delete.php (POST): delete user account -- post/ (GET/POST): get single post by id -- post/list.php (GET/POST): get list of posts from range -- post/create.php (POST): create new post with image -- post/edit.php (POST): edit tags of post -- post/delete.php (POST): delete post -- post/vote.php (POST): rate the existing post +- [ ] post/ (GET/POST): get single post by id +- [ ] post/search.php (GET/POST): get list of posts matching the criteria +- [ ] post/create.php (POST): create new post with image +- [ ] post/edit.php (POST): edit tags of post +- [ ] post/delete.php (POST): delete post +- [ ] post/vote.php (POST): rate the existing post -- comments/ (GET/POST): show all comments from section by id -- comments/create.php (POST): create new comment at selected section -- comments/edit.php (POST): edit existing comment -- comments/delete.php (POST): remove existing comment \ No newline at end of file +- [ ] comments/ (GET/POST): show all comments from section by id +- [ ] comments/create.php (POST): create new comment at selected section +- [ ] comments/edit.php (POST): edit existing comment +- [ ] comments/delete.php (POST): remove existing comment \ No newline at end of file