1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 17:26:43 +00:00

Update BaseApiController

This commit is contained in:
Daniel Supernault 2019-04-30 22:51:50 -06:00
parent 4b1ac4a6ef
commit 60ead2bab3
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -32,6 +32,7 @@ use App\Jobs\VideoPipeline\{
VideoPostProcess,
VideoThumbnail
};
use App\Services\NotificationService;
class BaseApiController extends Controller
{
@ -47,6 +48,7 @@ class BaseApiController extends Controller
public function notifications(Request $request)
{
$pid = Auth::user()->profile->id;
if(config('exp.ns') == false) {
$timeago = Carbon::now()->subMonths(6);
$notifications = Notification::whereProfileId($pid)
->whereDate('created_at', '>', $timeago)
@ -54,6 +56,20 @@ class BaseApiController extends Controller
->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);
}