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

This commit is contained in:
Daniel Supernault 2019-09-24 20:05:40 -06:00
parent 6afd69702a
commit 41c91cba43
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 38 additions and 1 deletions

View file

@ -34,6 +34,7 @@ class ApiV1Controller extends Controller
$this->fractal = new Fractal\Manager(); $this->fractal = new Fractal\Manager();
$this->fractal->setSerializer(new ArraySerializer()); $this->fractal->setSerializer(new ArraySerializer());
} }
public function apps(Request $request) public function apps(Request $request)
{ {
abort_if(!config('pixelfed.oauth_enabled'), 404); abort_if(!config('pixelfed.oauth_enabled'), 404);
@ -69,6 +70,13 @@ class ApiV1Controller extends Controller
return $res; return $res;
} }
/**
* GET /api/v1/accounts/{id}
*
* @param integer $id
*
* @return \App\Transformer\Api\AccountTransformer
*/
public function accountById(Request $request, $id) public function accountById(Request $request, $id)
{ {
$profile = Profile::whereNull('status')->findOrFail($id); $profile = Profile::whereNull('status')->findOrFail($id);
@ -78,6 +86,11 @@ class ApiV1Controller extends Controller
return response()->json($res); return response()->json($res);
} }
/**
* PATCH /api/v1/accounts/update_credentials
*
* @return \App\Transformer\Api\AccountTransformer
*/
public function accountUpdateCredentials(Request, $request) public function accountUpdateCredentials(Request, $request)
{ {
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
@ -128,6 +141,30 @@ class ApiV1Controller extends Controller
return response()->json($res); return response()->json($res);
} }
/**
* GET /api/v1/accounts/{id}/followers
*
* @param integer $id
*
* @return \App\Transformer\Api\AccountTransformer
*/
public function accountFollowersById(Request $request, $id)
{
abort_if(!$request->user(), 403);
$profile = Profile::whereNull('status')->findOrFail($id);
$settings = $profile->user->settings;
if($settings->show_profile_followers == true) {
$limit = $request->input('limit') ?? 40;
$followers = $profile->followers()->paginate($limit);
$resource = new Fractal\Resource\Collection($followers, 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

@ -82,7 +82,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
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', 'PublicApiController@accountFollowing')->middleware('auth:api');
Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers')->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');
Route::post('avatar/update', 'ApiController@avatarUpdate')->middleware('auth:api'); Route::post('avatar/update', 'ApiController@avatarUpdate')->middleware('auth:api');