mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add /api/v1/statuses/{id}/unfavourite endpoint
This commit is contained in:
parent
4edeba17ba
commit
437e18e3ad
2 changed files with 29 additions and 0 deletions
|
@ -704,6 +704,34 @@ class ApiV1Controller extends Controller
|
|||
return response()->json($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/v1/statuses/{id}/unfavourite
|
||||
*
|
||||
* @param integer $id
|
||||
*
|
||||
* @return \App\Transformer\Api\StatusTransformer
|
||||
*/
|
||||
public function statusUnfavouriteById(Request $request, $id)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
$status = Status::findOrFail($id);
|
||||
|
||||
$like = Like::whereProfileId($user->profile_id)
|
||||
->whereStatusId($status->id)
|
||||
->first();
|
||||
|
||||
if($like) {
|
||||
$like->delete();
|
||||
}
|
||||
|
||||
$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);
|
||||
|
|
|
@ -101,6 +101,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
|||
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::post('statuses/{id}/unfavourite', 'Api\ApiV1Controller@statusUnfavouriteById')->middleware('auth:api');
|
||||
|
||||
Route::get('likes', 'ApiController@hydrateLikes');
|
||||
Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');
|
||||
|
|
Loading…
Reference in a new issue