From 9a50a6f6278aee80f4aee737865d7cb75c967fd6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 1 Oct 2019 21:52:27 -0600 Subject: [PATCH 1/3] Update ApiController --- app/Http/Controllers/Api/ApiV1Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index ea4a4258..0c452663 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1164,14 +1164,14 @@ class ApiV1Controller extends Controller $id = $min ?? $max; $notifications = Notification::whereProfileId($pid) ->whereDate('created_at', '>', $timeago) - ->latest() ->where('id', $dir, $id) + ->orderByDesc('created_at') ->limit($limit) ->get(); } else { $notifications = Notification::whereProfileId($pid) ->whereDate('created_at', '>', $timeago) - ->latest() + ->orderByDesc('created_at') ->simplePaginate($limit); } $resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer()); From 8752d213010a644c55d4902dd010fabe62cb7222 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 1 Oct 2019 22:24:59 -0600 Subject: [PATCH 2/3] Update ApiController --- app/Http/Controllers/Api/ApiV1Controller.php | 27 +++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 0c452663..4a90cee4 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1431,6 +1431,7 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ + 'page' => 'nullable|integer|min:1|max:40' 'limit' => 'nullable|integer|min:1|max:80' ]); @@ -1440,7 +1441,15 @@ class ApiV1Controller extends Controller $resource = new Fractal\Resource\Collection($shared, new AccountTransformer()); $res = $this->fractal->createData($resource)->toArray(); - return response()->json($res); + $url = $request->url(); + $page = $request->input('page', 1); + $next = $page < 40 ? $page + 1 : 40; + $prev = $page > 1 ? $page - 1 : 1; + $links = '<'.$url.'?page='.$next.'&limit='.$limit.'>; rel="next", <'.$url.'?page='.$prev.'&limit='.$limit.'>; rel="prev"'; + + return response() + ->header('Link', $links) + ->json($res); } /** @@ -1455,6 +1464,7 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ + 'page' => 'nullable|integer|min:1|max:40' 'limit' => 'nullable|integer|min:1|max:80' ]); @@ -1464,7 +1474,15 @@ class ApiV1Controller extends Controller $resource = new Fractal\Resource\Collection($liked, new AccountTransformer()); $res = $this->fractal->createData($resource)->toArray(); - return response()->json($res); + $url = $request->url(); + $page = $request->input('page', 1); + $next = $page < 40 ? $page + 1 : 40; + $prev = $page > 1 ? $page - 1 : 1; + $links = '<'.$url.'?page='.$next.'&limit='.$limit.'>; rel="next", <'.$url.'?page='.$prev.'&limit='.$limit.'>; rel="prev"'; + + return response() + ->header('Link', $links) + ->json($res); } /** @@ -1608,6 +1626,8 @@ class ApiV1Controller extends Controller ]); if($share->wasRecentlyCreated == true) { + $status->reblogs_count = $status->shares()->count(); + $status->save(); SharePipeline::dispatch($share); } @@ -1633,8 +1653,7 @@ class ApiV1Controller extends Controller Status::whereProfileId($user->profile_id) ->whereReblogOfId($status->id) ->delete(); - $count = $status->reblogs_count; - $status->reblogs_count = $count > 0 ? $count - 1 : 0; + $status->reblogs_count = $status->shares()->count(); $status->save(); $resource = new Fractal\Resource\Item($status, new StatusTransformer()); From 7c17c0e4ffdb82b8c831f6c69980842ec960929c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 1 Oct 2019 22:31:29 -0600 Subject: [PATCH 3/3] Update ApiController, oof --- app/Http/Controllers/Api/ApiV1Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 4a90cee4..df3a648c 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1431,7 +1431,7 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'page' => 'nullable|integer|min:1|max:40' + 'page' => 'nullable|integer|min:1|max:40', 'limit' => 'nullable|integer|min:1|max:80' ]); @@ -1464,7 +1464,7 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'page' => 'nullable|integer|min:1|max:40' + 'page' => 'nullable|integer|min:1|max:40', 'limit' => 'nullable|integer|min:1|max:80' ]);