mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Add /api/v1/accounts/relationships endpoint
This commit is contained in:
parent
4c7fbe9a08
commit
4b9f7d6b14
2 changed files with 28 additions and 2 deletions
|
@ -442,6 +442,32 @@ class ApiV1Controller extends Controller
|
|||
return response()->json($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/accounts/relationships
|
||||
*
|
||||
* @param array|integer $id
|
||||
*
|
||||
* @return \App\Transformer\Api\RelationshipTransformer
|
||||
*/
|
||||
public function accountRelationshipsById(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'id' => 'required|array|min:1|max:20',
|
||||
'id.*' => 'required|integer|min:1|max:' . PHP_INT_MAX
|
||||
]);
|
||||
$pid = $request->user()->profile_id ?? $request->user()->profile->id;
|
||||
$ids = collect($request->input('id'));
|
||||
$filtered = $ids->filter(function($v) use($pid) {
|
||||
return $v != $pid;
|
||||
});
|
||||
$relations = Profile::whereNull('status')->findOrFail($filtered->values());
|
||||
$fractal = new Fractal\Resource\Collection($relations, new RelationshipTransformer());
|
||||
$res = $this->fractal->createData($fractal)->toArray();
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
public function statusById(Request $request, $id)
|
||||
{
|
||||
$status = Status::whereVisibility('public')->findOrFail($id);
|
||||
|
|
|
@ -79,7 +79,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
|||
Route::group(['prefix' => 'v1'], function () {
|
||||
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials')->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', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api');
|
||||
Route::get('accounts/{id}/statuses', 'Api\ApiV1Controller@accountStatusesById')->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');
|
||||
|
@ -115,7 +115,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
|||
Route::group(['prefix' => 'pixelfed'], function() {
|
||||
Route::group(['prefix' => 'v1'], function() {
|
||||
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials');
|
||||
Route::get('accounts/relationships', 'PublicApiController@relationships');
|
||||
Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById');
|
||||
Route::get('accounts/{id}/statuses', 'PublicApiController@accountStatuses');
|
||||
Route::get('accounts/{id}/following', 'PublicApiController@accountFollowing');
|
||||
Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers');
|
||||
|
|
Loading…
Reference in a new issue