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

This commit is contained in:
Daniel Supernault 2019-09-27 01:01:48 -06:00
parent 118006ed2d
commit 5cdff57d59
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 25 additions and 0 deletions

View file

@ -1437,6 +1437,30 @@ class ApiV1Controller extends Controller
return response()->json($res); return response()->json($res);
} }
/**
* GET /api/v1/statuses/{id}/favourited_by
*
* @param integer $id
*
* @return AccountTransformer
*/
public function statusFavouritedBy(Request $request, $id)
{
abort_if(!$request->user(), 403);
$this->validate($request, [
'limit' => 'nullable|integer|min:1|max:80'
]);
$limit = $request->input('limit') ?? 40;
$status = Status::whereVisibility('public')->findOrFail($id);
$liked = $status->likedBy()->latest()->simplePaginate($limit);
$resource = new Fractal\Resource\Collection($liked, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
public function createStatus(Request $request) public function createStatus(Request $request)
{ {
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);

View file

@ -120,6 +120,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('statuses/{id}/context', 'Api\ApiV1Controller@statusContext')->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('statuses/{id}/card', 'Api\ApiV1Controller@statusCard')->middleware('auth:api');
Route::get('statuses/{id}/reblogged_by', 'Api\ApiV1Controller@statusRebloggedBy')->middleware('auth:api'); Route::get('statuses/{id}/reblogged_by', 'Api\ApiV1Controller@statusRebloggedBy')->middleware('auth:api');
Route::get('statuses/{id}/favourited_by', 'Api\ApiV1Controller@statusFavouritedBy')->middleware('auth:api');
Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware('auth:api'); Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware('auth:api');
Route::get('conversations', 'Api\ApiV1Controller@conversations')->middleware('auth:api'); Route::get('conversations', 'Api\ApiV1Controller@conversations')->middleware('auth:api');