Add /api/v1/statuses/{id}/unreblog endpoint

This commit is contained in:
Daniel Supernault 2019-09-29 01:11:31 -06:00
parent 43cef28296
commit 3147fe5ca3
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 28 additions and 1 deletions

View file

@ -1607,7 +1607,33 @@ class ApiV1Controller extends Controller
SharePipeline::dispatch($share); SharePipeline::dispatch($share);
} }
$resource = new Fractal\Resource\Item($share, new StatusTransformer()); $resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
/**
* POST /api/v1/statuses/{id}/unreblog
*
* @param integer $id
*
* @return StatusTransformer
*/
public function statusUnshare(Request $request, $id)
{
abort_if(!$request->user(), 403);
$user = $request->user();
$status = Status::findOrFail($id);
Status::whereProfileId($user->profile_id)
->whereReblogOfId($status->id)
->delete();
$count = $status->reblogs_count;
$status->reblogs_count = $count > 0 ? $count - 1 : 0;
$status->save();
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray(); $res = $this->fractal->createData($resource)->toArray();
return response()->json($res); return response()->json($res);
} }

View file

@ -128,6 +128,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::post('statuses', 'Api\ApiV1Controller@statusCreate')->middleware('auth:api'); Route::post('statuses', 'Api\ApiV1Controller@statusCreate')->middleware('auth:api');
Route::delete('statuses/{id}', 'Api\ApiV1Controller@statusDelete')->middleware('auth:api'); Route::delete('statuses/{id}', 'Api\ApiV1Controller@statusDelete')->middleware('auth:api');
Route::post('statuses/{id}/reblog', 'Api\ApiV1Controller@statusShare')->middleware('auth:api'); Route::post('statuses/{id}/reblog', 'Api\ApiV1Controller@statusShare')->middleware('auth:api');
Route::post('statuses/{id}/unreblog', 'Api\ApiV1Controller@statusUnshare')->middleware('auth:api');
// Route::get('likes', 'ApiController@hydrateLikes'); // Route::get('likes', 'ApiController@hydrateLikes');
// Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api'); // Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');