diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 3f9f66bd..615493be 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Str; use App\Util\ActivityPub\Helpers; +use App\Jobs\LikePipeline\LikePipeline; use App\Jobs\StatusPipeline\StatusDelete; use App\Jobs\FollowPipeline\FollowPipeline; use Laravel\Passport\Passport; @@ -652,9 +653,9 @@ class ApiV1Controller extends Controller /** * GET /api/v1/favourites * - * Return empty array + * Returns collection of liked statuses * - * @return array + * @return \App\Transformer\Api\StatusTransformer */ public function accountFavourites(Request $request) { @@ -674,6 +675,35 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * POST /api/v1/statuses/{id}/favourite + * + * @param integer $id + * + * @return \App\Transformer\Api\StatusTransformer + */ + public function statusFavouriteById(Request $request, $id) + { + abort_if(!$request->user(), 403); + + $user = $request->user(); + + $status = Status::findOrFail($id); + + $like = Like::firstOrCreate([ + 'profile_id' => $user->profile_id, + 'status_id' => $status->id + ]); + + if($like->wasRecentlyCreated == true) { + LikePipeline::dispatch($like); + } + + $resource = new Fractal\Resource\Item($status, 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 fb0866c4..cfd4bb28 100644 --- a/routes/web.php +++ b/routes/web.php @@ -100,6 +100,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact 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::post('statuses/{id}/favourite', 'Api\ApiV1Controller@statusFavouriteById')->middleware('auth:api'); + Route::get('likes', 'ApiController@hydrateLikes'); Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api'); Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api');