Update BaseApiController, improve favourites endpoint

This commit is contained in:
Daniel Supernault 2022-01-26 23:32:31 -07:00
parent 3c35158ebc
commit f063cb0185
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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)