rpicms

A CMS for the Raspberry Pi
git clone git://archive.git.mtrnord.blog/RpicmsTeam/rpicms.git
Log | Files | Refs | README | LICENSE

commit c059b83fd8ce9938c166115eefb219e26e903c3d
parent c6ecac1ed72a4ec0b6e766c48f69d327bd0161ff
Author: MTRNord <mtrnord1@gmail.com>
Date:   Wed, 18 Mar 2015 20:40:44 +0100

first try to get specific posts

Diffstat:
Mcore/api/v1/DbHandler.class.php | 17+++++++++++------
Mcore/api/v1/api.php | 12+++++++-----
2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/core/api/v1/DbHandler.class.php b/core/api/v1/DbHandler.class.php @@ -204,7 +204,7 @@ class DbHandler { return md5(uniqid(rand(), true)); } - /* ------------- `tasks` table method ------------------ */ + /* ------------- `posts` table method ------------------ */ /** * Creating new task @@ -239,16 +239,21 @@ class DbHandler { * Fetching single task * @param String $task_id id of the task */ - public function getPosts($task_id) { - $stmt = $this->conn->prepare("SELECT t.id, t.task, t.status, t.created_at from tasks t, user_tasks ut WHERE t.id = ? AND ut.task_id = t.id AND ut.user_id = ?"); - $stmt->bind_param("ii", $task_id); + public function getPosts($post_id) { + if ($post_id = NULL){ + return $all; + }else{ + $stmt = $this->conn->prepare("SELECT id,title,text,author,category,date FROM posts WHERE id LIKE '$post_id'"); + $stmt->bind_param("ii", $post_id); if ($stmt->execute()) { - $task = $stmt->get_result()->fetch_assoc(); + $post = $stmt->get_result()->fetch_assoc(); $stmt->close(); - return $task; + return $post; } else { return NULL; } + } + } /** diff --git a/core/api/v1/api.php b/core/api/v1/api.php @@ -146,20 +146,22 @@ $app->post('/login', function() use ($app) { * url /posts/:id * Will return 404 if the task doesn't belongs to user */ -$app->get('/posts/:id', function($task_id) { +$app->get('/posts/:id', function($post_id) { global $user_id; $response = array(); $db = new DbHandler(); // fetch task - $result = $db->getPosts($task_id); + $result = $db->getPosts($post_id); if ($result != NULL) { $response["error"] = false; $response["id"] = $result["id"]; - $response["task"] = $result["task"]; - $response["status"] = $result["status"]; - $response["createdAt"] = $result["created_at"]; + $response["title"] = $result["title"]; + $response["text"] = $result["text"]; + $response["author"] = $result["author"]; + $response["category"] = $result["category"]; + $response["date"] = $result["date"]; echoRespnse(200, $response); } else { $response["error"] = true;