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