Skip to content

Commit

Permalink
Add /api/v1/accounts/{id}/unblock endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Sep 25, 2019
1 parent f4952e2 commit 35226c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/Http/Controllers/Api/ApiV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
FollowRequest,
Like,
Media,
Notification,
Profile,
Status,
UserFilter,
Expand Down Expand Up @@ -575,6 +576,41 @@ public function accountBlockById(Request $request, $id)
return response()->json($res);
}

/**
* POST /api/v1/accounts/{id}/unblock
*
* @param integer $id
*
* @return \App\Transformer\Api\RelationshipTransformer
*/
public function accountUnblockById(Request $request, $id)
{
abort_if(!$request->user(), 403);

$user = $request->user();
$pid = $user->profile_id ?? $user->profile->id;

if($id == $pid) {
abort(400, 'You cannot unblock yourself');
}

$profile = Profile::findOrFail($id);

UserFilter::whereUserId($pid)
->whereFilterableId($profile->id)
->whereFilterableType('App\Profile')
->whereFilterType('block')
->delete();

Cache::forget("user:filter:list:$pid");
Cache::forget("api:local:exp:rec:$pid");

$resource = new Fractal\Resource\Item($profile, new RelationshipTransformer());
$res = $this->fractal->createData($resource)->toArray();

return response()->json($res);
}

public function statusById(Request $request, $id)
{
$status = Status::whereVisibility('public')->findOrFail($id);
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
Route::post('accounts/{id}/unfollow', 'Api\ApiV1Controller@accountUnfollowById')->middleware('auth:api');
Route::get('blocks', 'Api\ApiV1Controller@accountBlocks')->middleware('auth:api');
Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById')->middleware('auth:api');
Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById')->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');
Expand Down

0 comments on commit 35226c9

Please sign in to comment.