From f4039ce218f93a5578225dfdba66f0359c8fc72c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 30 Sep 2019 20:53:14 -0600 Subject: [PATCH] Update BaseApiController --- .../Controllers/Api/BaseApiController.php | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index 7874ed2db..3d70d4b7f 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -49,18 +49,26 @@ class BaseApiController extends Controller { abort_if(!$request->user(), 403); $pid = $request->user()->profile_id; - $this->validate($request, [ - 'page' => 'nullable|integer|min:1|max:10', - 'limit' => 'nullable|integer|min:1|max:40' - ]); - $limit = $request->input('limit') ?? 10; - $timeago = Carbon::now()->subMonths(6); - $notifications = Notification::whereProfileId($pid) - ->whereDate('created_at', '>', $timeago) - ->latest() - ->simplePaginate($limit); - $resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer()); - $res = $this->fractal->createData($resource)->toArray(); + $pg = $request->input('pg'); + if($pg == true) { + $timeago = Carbon::now()->subMonths(6); + $notifications = Notification::whereProfileId($pid) + ->whereDate('created_at', '>', $timeago) + ->latest() + ->simplePaginate(10); + $resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + } else { + $this->validate($request, [ + 'page' => 'nullable|integer|min:1|max:10', + 'limit' => 'nullable|integer|min:1|max:40' + ]); + $limit = $request->input('limit') ?? 10; + $page = $request->input('page') ?? 1; + $end = (int) $page * $limit; + $start = (int) $end - $limit; + $res = NotificationService::get($pid, $start, $end); + } return response()->json($res); } @@ -307,13 +315,6 @@ class BaseApiController extends Controller $profile = Profile::whereNull('status')->whereUserId($id)->firstOrFail(); $resource = new Fractal\Resource\Item($profile, new AccountTransformer()); $res = $this->fractal->createData($resource)->toArray(); - $res['source'] = [ - 'privacy' => $profile->is_private ? 'private' : 'public', - 'sensitive' => $profile->cw ? true : false, - 'language' => 'en', - 'note' => '', - 'fields' => [] - ]; return $res; });