forked from mirror/pixelfed
Update BaseApiController
This commit is contained in:
parent
4b1ac4a6ef
commit
60ead2bab3
1 changed files with 23 additions and 7 deletions
|
@ -32,6 +32,7 @@ use App\Jobs\VideoPipeline\{
|
||||||
VideoPostProcess,
|
VideoPostProcess,
|
||||||
VideoThumbnail
|
VideoThumbnail
|
||||||
};
|
};
|
||||||
|
use App\Services\NotificationService;
|
||||||
|
|
||||||
class BaseApiController extends Controller
|
class BaseApiController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -47,13 +48,28 @@ class BaseApiController extends Controller
|
||||||
public function notifications(Request $request)
|
public function notifications(Request $request)
|
||||||
{
|
{
|
||||||
$pid = Auth::user()->profile->id;
|
$pid = Auth::user()->profile->id;
|
||||||
$timeago = Carbon::now()->subMonths(6);
|
if(config('exp.ns') == false) {
|
||||||
$notifications = Notification::whereProfileId($pid)
|
$timeago = Carbon::now()->subMonths(6);
|
||||||
->whereDate('created_at', '>', $timeago)
|
$notifications = Notification::whereProfileId($pid)
|
||||||
->latest()
|
->whereDate('created_at', '>', $timeago)
|
||||||
->simplePaginate(10);
|
->latest()
|
||||||
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
|
->simplePaginate(10);
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
$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);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue