mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-11 14:40:46 +00:00
Update BaseApiController
This commit is contained in:
parent
30402f8602
commit
6fbbe3202e
1 changed files with 12 additions and 20 deletions
|
@ -49,26 +49,18 @@ class BaseApiController extends Controller
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$pg = $request->input('pg');
|
$this->validate($request, [
|
||||||
if($pg == true) {
|
'page' => 'nullable|integer|min:1|max:10',
|
||||||
$timeago = Carbon::now()->subMonths(6);
|
'limit' => 'nullable|integer|min:1|max:40'
|
||||||
$notifications = Notification::whereProfileId($pid)
|
]);
|
||||||
->whereDate('created_at', '>', $timeago)
|
$limit = $request->input('limit') ?? 10;
|
||||||
->latest()
|
$timeago = Carbon::now()->subMonths(6);
|
||||||
->simplePaginate(10);
|
$notifications = Notification::whereProfileId($pid)
|
||||||
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
|
->whereDate('created_at', '>', $timeago)
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
->latest()
|
||||||
} else {
|
->simplePaginate($limit);
|
||||||
$this->validate($request, [
|
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
|
||||||
'page' => 'nullable|integer|min:1|max:10',
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
'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);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue