From a0323f63056d1100041f84b7efba5e38481ece30 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Sat, 5 Oct 2024 14:16:39 +0300 Subject: [PATCH] add edit comments --- app/Controllers/Api/Images/Comments/Edit.php | 35 ++++++ app/Controllers/ApiController.php | 4 + app/Core/Routes.php | 1 + app/Models/Comment.php | 4 +- static/js/act.js | 115 ++++++++++++------- 5 files changed, 114 insertions(+), 45 deletions(-) create mode 100644 app/Controllers/Api/Images/Comments/Edit.php diff --git a/app/Controllers/Api/Images/Comments/Edit.php b/app/Controllers/Api/Images/Comments/Edit.php new file mode 100644 index 0000000..816ba8c --- /dev/null +++ b/app/Controllers/Api/Images/Comments/Edit.php @@ -0,0 +1,35 @@ + $postId))[0]['user_id']; + if ($postuserid === Auth::userid()) { + $json = file_get_contents('php://input'); + $data = json_decode($json, true); + DB::query('UPDATE photos_comments SET body=:body WHERE id=:id', array(':id' => $postId, ':body' => $data['value'])); + echo json_encode( + array( + 'errorcode' => '0', + 'error' => 0, + 'postid' => $postId + ) + ); + } else { + echo json_encode( + array( + 'errorcode' => '1', + 'error' => 1 + ) + ); + } + } +} diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 0fb491b..1e2acef 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -13,6 +13,7 @@ use \App\Controllers\Api\Images\CheckAll as PhotoCheckAll; use \App\Controllers\Api\Images\LoadRecent as PhotoLoadRecent; use \App\Controllers\Api\Images\Stats as PhotoStats; use \App\Controllers\Api\Images\Comments\Create as PhotoComment; +use \App\Controllers\Api\Images\Comments\Edit as PhotoCommentEdit; use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad; use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote; use \App\Controllers\Api\Profile\Update as ProfileUpdate; @@ -39,6 +40,9 @@ class ApiController public static function photocomment() { return new PhotoComment(); } + public static function photocommentedit() { + return new PhotoCommentEdit(); + } public static function photocommentvote() { return new PhotoCommentVote(); } diff --git a/app/Core/Routes.php b/app/Core/Routes.php index de702d0..221d69f 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -53,6 +53,7 @@ class Routes Router::get('/api/photo/vote', 'ApiController@photovote'); Router::get('/api/photo/checkall', 'ApiController@checkallphotos'); Router::get('/api/photo/comment/rate', 'ApiController@photocommentvote'); + Router::post('/api/photo/comment/$id/edit', 'ApiController@photocommentedit'); if ($user->i('admin') > 0) { Router::any('/admin', 'AdminController@index'); Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis'); diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 5e1115f..ad8dbcc 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -76,8 +76,8 @@ class Comment {