From 60ead2bab3b5206652828678a12d695cea94c054 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 30 Apr 2019 22:51:50 -0600 Subject: [PATCH] Update BaseApiController --- .../Controllers/Api/BaseApiController.php | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index 5ae8f9f68..3110aad7d 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -32,6 +32,7 @@ use App\Jobs\VideoPipeline\{ VideoPostProcess, VideoThumbnail }; +use App\Services\NotificationService; class BaseApiController extends Controller { @@ -47,13 +48,28 @@ class BaseApiController extends Controller public function notifications(Request $request) { $pid = Auth::user()->profile->id; - $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(); + if(config('exp.ns') == false) { + $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', + 'limit' => 'nullable|integer|min:1|max:10' + ]); + $limit = $request->input('limit') ?? 10; + $page = $request->input('page') ?? 1; + if($page > 3) { + return response()->json([]); + } + $end = (int) $page * $limit; + $start = (int) $end - $limit; + $res = NotificationService::get($pid, $start, $end); + } return response()->json($res); }