From b9cc06daa5a9910c1dc42de4bb48265d0ab26572 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 25 Sep 2019 13:46:47 -0600 Subject: [PATCH] Add /api/v1/favourites endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 25 ++++++++++++++++++++ routes/web.php | 1 + 2 files changed, 26 insertions(+) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 7254df1e..3f9f66bd 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -649,6 +649,31 @@ class ApiV1Controller extends Controller 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) { $status = Status::whereVisibility('public')->findOrFail($id); diff --git a/routes/web.php b/routes/web.php index 0e4706b3..fb0866c4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -99,6 +99,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('endorsements', 'Api\ApiV1Controller@accountEndorsements')->middleware('auth:api'); Route::get('blocks', 'Api\ApiV1Controller@accountBlocks')->middleware('auth:api'); Route::get('custom_emojis', 'Api\ApiV1Controller@customEmojis'); + Route::get('favourites', 'Api\ApiV1Controller@accountFavourites')->middleware('auth:api'); Route::get('likes', 'ApiController@hydrateLikes'); Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api'); Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api');