From 607eb51b4e44c1ce2188b80a666c343d3751329b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 24 Sep 2019 20:08:44 -0600 Subject: [PATCH] Add /api/v1/accounts/{id}/following endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 24 ++++++++++++++++++++ routes/web.php | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 3f8630bee..a1a3fc60d 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -165,6 +165,30 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * GET /api/v1/accounts/{id}/following + * + * @param integer $id + * + * @return \App\Transformer\Api\AccountTransformer + */ + public function accountFollowingById(Request $request, $id) + { + abort_if(!$request->user(), 403); + $profile = Profile::whereNull('status')->findOrFail($id); + + $settings = $profile->user->settings; + if($settings->show_profile_following == true) { + $limit = $request->input('limit') ?? 40; + $following = $profile->following()->paginate($limit); + $resource = new Fractal\Resource\Collection($following, new AccountTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + } else { + $res = []; + } + return response()->json($res); + } + public function statusById(Request $request, $id) { $status = Status::whereVisibility('public')->findOrFail($id); diff --git a/routes/web.php b/routes/web.php index d20bae191..1d461670a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -81,7 +81,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware('auth:api'); Route::get('accounts/relationships', 'PublicApiController@relationships')->middleware('auth:api'); Route::get('accounts/{id}/statuses', 'PublicApiController@accountStatuses')->middleware('auth:api'); - Route::get('accounts/{id}/following', 'PublicApiController@accountFollowing')->middleware('auth:api'); + Route::get('accounts/{id}/following', 'Api\ApiV1Controller@accountFollowingById')->middleware('auth:api'); Route::get('accounts/{id}/followers', 'Api\ApiV1Controller@accountFollowersById')->middleware('auth:api'); // Route::get('accounts/{id}', 'PublicApiController@account'); Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById');