mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add /api/v1/statuses/{id}/favourite endpoint
This commit is contained in:
parent
969e2f0296
commit
4edeba17ba
2 changed files with 34 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue