From 9225120835ba814c1607a1094926c0f9bc967bda Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 26 Sep 2019 23:19:57 -0600 Subject: [PATCH] Add /api/v1/statuses/{id}/card endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 62 ++++++++++++++++---- routes/api.php | 2 - routes/web.php | 4 ++ 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 535c0cb87..3b017ad9d 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -927,7 +927,7 @@ class ApiV1Controller extends Controller * POST /api/v1/media * * - * @return App\Transformer\Api\MediaTransformer + * @return MediaTransformer */ public function mediaUpload(Request $request) { @@ -1011,7 +1011,7 @@ class ApiV1Controller extends Controller * * @param integer $id * - * @return App\Transformer\Api\MediaTransformer + * @return MediaTransformer */ public function mediaUpdate(Request $request, $id) { @@ -1041,7 +1041,7 @@ class ApiV1Controller extends Controller * GET /api/v1/mutes * * - * @return App\Transformer\Api\AccountTransformer + * @return AccountTransformer */ public function accountMutes(Request $request) { @@ -1072,7 +1072,7 @@ class ApiV1Controller extends Controller * * @param integer $id * - * @return App\Transformer\Api\RelationshipTransformer + * @return RelationshipTransformer */ public function accountMuteById(Request $request, $id) { @@ -1104,7 +1104,7 @@ class ApiV1Controller extends Controller * * @param integer $id * - * @return App\Transformer\Api\RelationshipTransformer + * @return RelationshipTransformer */ public function accountUnmuteById(Request $request, $id) { @@ -1137,7 +1137,7 @@ class ApiV1Controller extends Controller * GET /api/v1/notifications * * - * @return App\Transformer\Api\NotificationTransformer + * @return NotificationTransformer */ public function accountNotifications(Request $request) { @@ -1177,7 +1177,7 @@ class ApiV1Controller extends Controller * GET /api/v1/timelines/home * * - * @return App\Transformer\Api\StatusTransformer + * @return StatusTransformer */ public function timelineHome(Request $request) { @@ -1279,7 +1279,7 @@ class ApiV1Controller extends Controller * GET /api/v1/timelines/public * * - * @return App\Transformer\Api\StatusTransformer + * @return StatusTransformer */ public function timelinePublic(Request $request) { @@ -1354,8 +1354,17 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * GET /api/v1/statuses/{id} + * + * @param integer $id + * + * @return StatusTransformer + */ public function statusById(Request $request, $id) { + abort_if(!$request->user(), 403); + $status = Status::whereVisibility('public')->findOrFail($id); $resource = new Fractal\Resource\Item($status, new StatusTransformer()); $res = $this->fractal->createData($resource)->toArray(); @@ -1363,9 +1372,42 @@ class ApiV1Controller extends Controller return response()->json($res); } - public function context(Request $request) + /** + * GET /api/v1/statuses/{id}/context + * + * @param integer $id + * + * @return StatusTransformer + */ + public function statusContext(Request $request, $id) { - // todo + abort_if(!$request->user(), 403); + + $status = Status::whereVisibility('public')->findOrFail($id); + + // Return empty response since we don't handle threading like this + $res = [ + 'ancestors' => [], + 'descendants' => [] + ]; + + return response()->json($res); + } + + /** + * GET /api/v1/statuses/{id}/card + * + * @param integer $id + * + * @return StatusTransformer + */ + public function statusCard(Request $request, $id) + { + abort_if(!$request->user(), 403); + + $status = Status::whereVisibility('public')->findOrFail($id); + + // Return empty response since we don't handle threading like this $res = [ 'ancestors' => [], 'descendants' => [] diff --git a/routes/api.php b/routes/api.php index da92e3bbe..78c263701 100644 --- a/routes/api.php +++ b/routes/api.php @@ -9,7 +9,5 @@ Route::group(['prefix' => 'api'], function() { Route::group(['prefix' => 'v1'], function() { Route::post('apps', 'Api\ApiV1Controller@apps'); Route::get('instance', 'Api\ApiV1Controller@instance'); - Route::get('statuses/{id}', 'Api\ApiV1Controller@statusById'); - Route::get('statuses/{id}/context', 'Api\ApiV1Controller@context'); }); }); diff --git a/routes/web.php b/routes/web.php index 2dd34256b..19ac6c7bc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -116,6 +116,10 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('accounts/{id}/unmute', 'Api\ApiV1Controller@accountUnmuteById')->middleware('auth:api'); Route::get('notifications', 'Api\ApiV1Controller@accountNotifications')->middleware('auth:api'); + Route::get('statuses/{id}', 'Api\ApiV1Controller@statusById')->middleware('auth:api'); + Route::get('statuses/{id}/context', 'Api\ApiV1Controller@statusContext')->middleware('auth:api'); + Route::get('statuses/{id}/card', 'Api\ApiV1Controller@statusCard')->middleware('auth:api'); + Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware('auth:api'); Route::get('conversations', 'Api\ApiV1Controller@conversations')->middleware('auth:api'); Route::get('timelines/public', 'Api\ApiV1Controller@timelinePublic');