From 00c61345d8918c95545eee94be0ed8d347be7a22 Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 25 Jan 2018 06:55:18 +0100 Subject: [PATCH] Created comments controller --- RestControllers/commentsController.php | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 RestControllers/commentsController.php diff --git a/RestControllers/commentsController.php b/RestControllers/commentsController.php new file mode 100644 index 0000000..004c062 --- /dev/null +++ b/RestControllers/commentsController.php @@ -0,0 +1,50 @@ +getPostCommentIDWithFullAccess("commentID"); + + //Try to delete the comment + if(!components()->comments->delete($commentID)) + Rest_fatal_error(500, "Coudln't delete comment!"); + + //Success + return array("success" => "The comment has been deleted!"); + + } + + /** + * Get a comment ID with full access + * + * @param string $name The name of the POST field containing + * the comment ID + * @return int The comment ID + */ + private function getPostCommentIDWithFullAccess($name) : int { + + //Get comment ID + $commentID = getPostCommentIDWithAccess($name); + + //Check the user is the owner of the comment + if(!components()->comments->is_owner(userID, $commentID)) + Rest_fatal_error(401, "You are not the owner of this comment !"); + + //Return comment ID + return $commentID; + } +} \ No newline at end of file