From ac9f1bc04e942fbeaffdc52bfe981d675af54cb6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 25 Sep 2019 00:46:06 -0600 Subject: [PATCH] Add /api/v1/blocks endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 34 +++++++++++++++++++- routes/web.php | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 545b5d0b1..1debc4ecd 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -500,7 +500,39 @@ class ApiV1Controller extends Controller $resource = new Fractal\Resource\Collection($profiles, new AccountTransformer()); $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) diff --git a/routes/web.php b/routes/web.php index c162c5ffe..ad649abed 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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::post('accounts/{id}/follow', 'Api\ApiV1Controller@accountFollowById')->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}', 'Api\ApiV1Controller@accountById'); 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}', 'PublicApiController@account'); Route::post('avatar/update', 'ApiController@avatarUpdate'); + Route::get('blocks', 'Api\ApiV1Controller@accountBlocks'); Route::get('likes', 'ApiController@hydrateLikes'); Route::post('media', 'ApiController@uploadMedia'); Route::delete('media', 'ApiController@deleteMedia');