Skip to content

Commit

Permalink
完成接口:/moments/delComment
Browse files Browse the repository at this point in the history
  • Loading branch information
Chef5 committed May 11, 2020
1 parent 4d9e354 commit 6a73cc0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/Http/Controllers/MomentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function delMoment(Request $request){
}
}

// 发表评论 遗留:缺少判断是否存在moid
// 发表评论
public function doComment(Request $request){
if($request->has('rid') && $request->has('moid') && $request->has('comment')){
$comment = new Comments();
Expand Down Expand Up @@ -130,6 +130,23 @@ public function doComment(Request $request){
}
}

// 删除评论
public function delComment(Request $request){
if($request->has('coid')){
DB::beginTransaction(); //事务开始
try {
Comments::where('coid', $request->coid)->delete(); //删除评论
DB::commit(); //提交事务
return returnData(true, "操作成功", null);
} catch (\Throwable $th) {
DB::rollback(); //回滚
return returnData(false, $th);
}
}else{
return returnData(false, "缺coid", null);
}
}

// 点赞
public function doLike(Request $request){
if($request->has('rid') && $request->has('moid')){
Expand Down
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
Route::post('/delMoment', 'MomentsController@delMoment');
// 发表评论
Route::post('/doComment', 'MomentsController@doComment');
// 删除评论
Route::get('delComment', 'MomentsController@delComment');
// 点赞
Route::post('/doLike', 'MomentsController@doLike');
// 取消点赞
Expand Down

0 comments on commit 6a73cc0

Please sign in to comment.