Add missing bookmark api endpoints

This commit is contained in:
Daniel Supernault 2020-05-19 14:55:26 -06:00
parent d398230b27
commit c74cd0bdf0
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 55 additions and 0 deletions

View file

@ -1901,6 +1901,59 @@ class ApiV1Controller extends Controller
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
}
/**
* POST /api/v1/statuses/{id}/bookmark
*
*
*
* @return StatusTransformer
*/
public function bookmarkStatus(Request $request, $id)
{
abort_if(!$request->user(), 403);
$status = Status::whereNull('uri')
->whereScope('public')
->findOrFail($id);
Bookmark::firstOrCreate([
'status_id' => $status->id,
'profile_id' => $request->user()->profile_id
]);
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
/**
* POST /api/v1/statuses/{id}/unbookmark
*
*
*
* @return StatusTransformer
*/
public function unbookmarkStatus(Request $request, $id)
{
abort_if(!$request->user(), 403);
$status = Status::whereNull('uri')
->whereScope('public')
->findOrFail($id);
Bookmark::firstOrCreate([
'status_id' => $status->id,
'profile_id' => $request->user()->profile_id
]);
$bookmark = Bookmark::whereStatusId($status->id)
->whereProfileId($request->user()->profile_id)
->firstOrFail();
$bookmark->delete();
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
/**
* GET /api/v2/search
*

View file

@ -60,6 +60,8 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
Route::get('statuses/{id}/favourited_by', 'Api\ApiV1Controller@statusFavouritedBy')->middleware($middleware);
Route::post('statuses/{id}/reblog', 'Api\ApiV1Controller@statusShare')->middleware($middleware);
Route::post('statuses/{id}/unreblog', 'Api\ApiV1Controller@statusUnshare')->middleware($middleware);
Route::post('statuses/{id}/bookmark', 'Api\ApiV1Controller@bookmarkStatus')->middleware($middleware);
Route::post('statuses/{id}/unbookmark', 'Api\ApiV1Controller@unbookmarkStatus')->middleware($middleware);
Route::delete('statuses/{id}', 'Api\ApiV1Controller@statusDelete')->middleware($middleware);
Route::get('statuses/{id}', 'Api\ApiV1Controller@statusById')->middleware($middleware);
Route::post('statuses', 'Api\ApiV1Controller@statusCreate')->middleware($middleware)->middleware('throttle:maxPostsPerHour,60')->middleware('throttle:maxPostsPerDay,1440');