Add /api/v1/favourites endpoint

This commit is contained in:
Daniel Supernault 2019-09-25 13:46:47 -06:00
parent fa4e291ad9
commit b9cc06daa5
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 26 additions and 0 deletions

View file

@ -649,6 +649,31 @@ class ApiV1Controller extends Controller
return response()->json([]); return response()->json([]);
} }
/**
* GET /api/v1/favourites
*
* Return empty array
*
* @return array
*/
public function accountFavourites(Request $request)
{
abort_if(!$request->user(), 403);
$user = $request->user();
$limit = $request->input('limit') ?? 20;
$favourites = Like::whereProfileId($user->profile_id)
->latest()
->simplePaginate($limit)
->pluck('status_id');
$statuses = Status::findOrFail($favourites);
$resource = new Fractal\Resource\Collection($statuses, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
public function statusById(Request $request, $id) public function statusById(Request $request, $id)
{ {
$status = Status::whereVisibility('public')->findOrFail($id); $status = Status::whereVisibility('public')->findOrFail($id);

View file

@ -99,6 +99,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('endorsements', 'Api\ApiV1Controller@accountEndorsements')->middleware('auth:api'); Route::get('endorsements', 'Api\ApiV1Controller@accountEndorsements')->middleware('auth:api');
Route::get('blocks', 'Api\ApiV1Controller@accountBlocks')->middleware('auth:api'); Route::get('blocks', 'Api\ApiV1Controller@accountBlocks')->middleware('auth:api');
Route::get('custom_emojis', 'Api\ApiV1Controller@customEmojis'); Route::get('custom_emojis', 'Api\ApiV1Controller@customEmojis');
Route::get('favourites', 'Api\ApiV1Controller@accountFavourites')->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');
Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api'); Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api');