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

This commit is contained in:
Daniel Supernault 2019-09-24 20:08:44 -06:00
parent 41c91cba43
commit 607eb51b4e
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 25 additions and 1 deletions

View file

@ -165,6 +165,30 @@ class ApiV1Controller extends Controller
return response()->json($res); 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) public function statusById(Request $request, $id)
{ {
$status = Status::whereVisibility('public')->findOrFail($id); $status = Status::whereVisibility('public')->findOrFail($id);

View file

@ -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::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware('auth:api');
Route::get('accounts/relationships', 'PublicApiController@relationships')->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}/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}/followers', 'Api\ApiV1Controller@accountFollowersById')->middleware('auth:api');
// Route::get('accounts/{id}', 'PublicApiController@account'); // Route::get('accounts/{id}', 'PublicApiController@account');
Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById'); Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById');