Add /api/v1/blocks endpoint

This commit is contained in:
Daniel Supernault 2019-09-25 00:46:06 -06:00
parent 5a0c295ed1
commit ac9f1bc04e
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 35 additions and 1 deletions

View file

@ -500,7 +500,39 @@ class ApiV1Controller extends Controller
$resource = new Fractal\Resource\Collection($profiles, new AccountTransformer()); $resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray(); $res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT); return response()->json($res);
}
/**
* GET /api/v1/blocks
*
*
*
* @return \App\Transformer\Api\AccountTransformer
*/
public function accountBlocks(Request $request)
{
abort_if(!$request->user(), 403);
$this->validate($request, [
'limit' => 'nullable|integer|min:1|max:40',
'page' => 'nullable|integer|min:1|max:10'
]);
$user = $request->user();
$limit = $request->input('limit') ?? 40;
$blocked = UserFilter::select('filterable_id','filterable_type','filter_type','user_id')
->whereUserId($user->profile_id)
->whereFilterableType('App\Profile')
->whereFilterType('block')
->simplePaginate($limit)
->pluck('filterable_id');
$profiles = Profile::findOrFail($blocked);
$resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
} }
public function statusById(Request $request, $id) public function statusById(Request $request, $id)

View file

@ -86,6 +86,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('accounts/{id}/followers', 'Api\ApiV1Controller@accountFollowersById')->middleware('auth:api'); Route::get('accounts/{id}/followers', 'Api\ApiV1Controller@accountFollowersById')->middleware('auth:api');
Route::post('accounts/{id}/follow', 'Api\ApiV1Controller@accountFollowById')->middleware('auth:api'); Route::post('accounts/{id}/follow', 'Api\ApiV1Controller@accountFollowById')->middleware('auth:api');
Route::post('accounts/{id}/unfollow', 'Api\ApiV1Controller@accountUnfollowById')->middleware('auth:api'); Route::post('accounts/{id}/unfollow', 'Api\ApiV1Controller@accountUnfollowById')->middleware('auth:api');
Route::get('blocks', 'Api\ApiV1Controller@accountBlocks')->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');
@ -123,6 +124,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers'); Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers');
Route::get('accounts/{id}', 'PublicApiController@account'); Route::get('accounts/{id}', 'PublicApiController@account');
Route::post('avatar/update', 'ApiController@avatarUpdate'); Route::post('avatar/update', 'ApiController@avatarUpdate');
Route::get('blocks', 'Api\ApiV1Controller@accountBlocks');
Route::get('likes', 'ApiController@hydrateLikes'); Route::get('likes', 'ApiController@hydrateLikes');
Route::post('media', 'ApiController@uploadMedia'); Route::post('media', 'ApiController@uploadMedia');
Route::delete('media', 'ApiController@deleteMedia'); Route::delete('media', 'ApiController@deleteMedia');