Browse Source

Add /api/v1/accounts/{id}/following endpoint

Daniel Supernault 5 years ago
parent
commit
607eb51b4e
2 changed files with 25 additions and 1 deletions
  1. 24 0
      app/Http/Controllers/Api/ApiV1Controller.php
  2. 1 1
      routes/web.php

+ 24 - 0
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);

+ 1 - 1
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');