From 29b1af100cbc38b693ac7b0f4f81c06ecc71d44c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 02:01:15 -0700 Subject: [PATCH] Update ApiV1Controller, add BookmarkService logic to bookmark endpoints --- app/Http/Controllers/Api/ApiV1Controller.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 8e9e7375..5dafa320 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2376,6 +2376,7 @@ class ApiV1Controller extends Controller $res['favourited'] = LikeService::liked($user->profile_id, $res['id']); $res['reblogged'] = ReblogService::get($user->profile_id, $res['id']); + $res['bookmarked'] = BookmarkService::get($user->profile_id, $res['id']); return $this->json($res); } @@ -3064,7 +3065,10 @@ class ApiV1Controller extends Controller 'status_id' => $status->id, 'profile_id' => $request->user()->profile_id ]); + + BookmarkService::add($request->user()->profile_id, $status->id); $res = StatusService::getMastodon($status->id); + $res['bookmarked'] = true; return $this->json($res); } @@ -3086,9 +3090,14 @@ class ApiV1Controller extends Controller $bookmark = Bookmark::whereStatusId($status->id) ->whereProfileId($request->user()->profile_id) - ->firstOrFail(); - $bookmark->delete(); + ->first(); + + if($bookmark) { + BookmarkService::del($request->user()->profile_id, $status->id); + $bookmark->delete(); + } $res = StatusService::getMastodon($status->id); + $res['bookmarked'] = false; return $this->json($res); }