From 3147fe5ca360baf7856b93e670fe14f50d8f806c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 29 Sep 2019 01:11:31 -0600 Subject: [PATCH] Add /api/v1/statuses/{id}/unreblog endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 28 +++++++++++++++++++- routes/web.php | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index bd94df4ab..ac99db92b 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1607,7 +1607,33 @@ class ApiV1Controller extends Controller 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(); return response()->json($res); } diff --git a/routes/web.php b/routes/web.php index 81ee42325..f1c1db510 100644 --- a/routes/web.php +++ b/routes/web.php @@ -128,6 +128,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('statuses', 'Api\ApiV1Controller@statusCreate')->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}/unreblog', 'Api\ApiV1Controller@statusUnshare')->middleware('auth:api'); // Route::get('likes', 'ApiController@hydrateLikes'); // Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');