Add /api/v1/statuses/{id}/unfavourite endpoint

This commit is contained in:
Daniel Supernault 2019-09-25 21:10:17 -06:00
parent 4edeba17ba
commit 437e18e3ad
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 29 additions and 0 deletions

View file

@ -704,6 +704,34 @@ class ApiV1Controller extends Controller
return response()->json($res); 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) public function statusById(Request $request, $id)
{ {
$status = Status::whereVisibility('public')->findOrFail($id); $status = Status::whereVisibility('public')->findOrFail($id);

View file

@ -101,6 +101,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
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('favourites', 'Api\ApiV1Controller@accountFavourites')->middleware('auth:api');
Route::post('statuses/{id}/favourite', 'Api\ApiV1Controller@statusFavouriteById')->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::get('likes', 'ApiController@hydrateLikes');
Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api'); Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');