1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pixelfed_ynh.git synced 2024-09-03 20:06:04 +02:00

Update BaseApiController

This commit is contained in:
Daniel Supernault 2019-09-30 20:53:14 -06:00
parent 4d084ac5de
commit f4039ce218
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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;
$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, [ $this->validate($request, [
'page' => 'nullable|integer|min:1|max:10', 'page' => 'nullable|integer|min:1|max:10',
'limit' => 'nullable|integer|min:1|max:40' 'limit' => 'nullable|integer|min:1|max:40'
]); ]);
$limit = $request->input('limit') ?? 10; $limit = $request->input('limit') ?? 10;
$timeago = Carbon::now()->subMonths(6); $page = $request->input('page') ?? 1;
$notifications = Notification::whereProfileId($pid) $end = (int) $page * $limit;
->whereDate('created_at', '>', $timeago) $start = (int) $end - $limit;
->latest() $res = NotificationService::get($pid, $start, $end);
->simplePaginate($limit); }
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
$res = $this->fractal->createData($resource)->toArray();
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;
}); });