Update BaseApiController, add favourites method

This commit is contained in:
Daniel Supernault 2020-12-09 22:23:51 -07:00
parent 1b2fd665bf
commit 76353ca997
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -11,8 +11,9 @@ use Auth, Cache, Storage, URL;
use Carbon\Carbon;
use App\{
Avatar,
Notification,
Like,
Media,
Notification,
Profile,
Status
};
@ -21,7 +22,8 @@ use App\Transformer\Api\{
NotificationTransformer,
MediaTransformer,
MediaDraftTransformer,
StatusTransformer
StatusTransformer,
StatusStatelessTransformer
};
use League\Fractal;
use App\Util\Media\Filter;
@ -338,4 +340,29 @@ class BaseApiController extends Controller
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
}
public function accountLikes(Request $request)
{
$user = $request->user();
abort_if(!$request->user(), 403);
$limit = 10;
$page = (int) $request->input('page', 1);
if($page > 20) {
return [];
}
$favourites = $user->profile->likes()
->latest()
->simplePaginate($limit)
->pluck('status_id');
$statuses = Status::find($favourites)->reverse();
$resource = new Fractal\Resource\Collection($statuses, new StatusStatelessTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
}
}