Add /api/v1/accounts/relationships endpoint

This commit is contained in:
Daniel Supernault 2019-09-24 23:26:26 -06:00
parent 4c7fbe9a08
commit 4b9f7d6b14
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 28 additions and 2 deletions

View file

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

View file

@ -79,7 +79,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::group(['prefix' => 'v1'], function () { Route::group(['prefix' => 'v1'], function () {
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials')->middleware('auth:api'); Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials')->middleware('auth:api');
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', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api');
Route::get('accounts/{id}/statuses', 'Api\ApiV1Controller@accountStatusesById')->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}/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');
@ -115,7 +115,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::group(['prefix' => 'pixelfed'], function() { Route::group(['prefix' => 'pixelfed'], function() {
Route::group(['prefix' => 'v1'], function() { Route::group(['prefix' => 'v1'], function() {
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials'); 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}/statuses', 'PublicApiController@accountStatuses');
Route::get('accounts/{id}/following', 'PublicApiController@accountFollowing'); Route::get('accounts/{id}/following', 'PublicApiController@accountFollowing');
Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers'); Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers');