mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update BaseApiController, improve favourites endpoint
This commit is contained in:
parent
3c35158ebc
commit
f063cb0185
1 changed files with 18 additions and 18 deletions
|
@ -259,27 +259,27 @@ class BaseApiController extends Controller
|
||||||
|
|
||||||
public function accountLikes(Request $request)
|
public function accountLikes(Request $request)
|
||||||
{
|
{
|
||||||
$user = $request->user();
|
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
|
$this->validate($request, [
|
||||||
|
'page' => 'sometimes|int|min:1|max:40',
|
||||||
|
'limit' => 'sometimes|int|min:1|max:10'
|
||||||
|
]);
|
||||||
|
|
||||||
$limit = 10;
|
$user = $request->user();
|
||||||
$page = (int) $request->input('page', 1);
|
$limit = $request->input('limit', 10);
|
||||||
|
|
||||||
if($page > 20) {
|
$res = \DB::table('likes')
|
||||||
return [];
|
->whereProfileId($user->profile_id)
|
||||||
}
|
->latest()
|
||||||
|
->simplePaginate($limit)
|
||||||
$favourites = $user->profile->likes()
|
->map(function($id) {
|
||||||
->latest()
|
return StatusService::get($id->status_id, false);
|
||||||
->simplePaginate($limit)
|
})
|
||||||
->pluck('status_id');
|
->filter(function($post) {
|
||||||
|
return $post && isset($post['account']);
|
||||||
$statuses = Status::find($favourites)->reverse();
|
})
|
||||||
|
->values();
|
||||||
$resource = new Fractal\Resource\Collection($statuses, new StatusStatelessTransformer());
|
return response()->json($res);
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
|
||||||
|
|
||||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function archive(Request $request, $id)
|
public function archive(Request $request, $id)
|
||||||
|
|
Loading…
Reference in a new issue