mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-24 14:03:16 +00:00
Update BaseApiController, add favourites method
This commit is contained in:
parent
1b2fd665bf
commit
76353ca997
1 changed files with 29 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue