1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Add subscription delete routes

This commit is contained in:
David Bomba 2021-04-11 13:52:37 +10:00
parent f5092e8cf4
commit 4ede6bd41e
2 changed files with 73 additions and 0 deletions

View File

@ -24,9 +24,12 @@ use App\Models\Subscription;
use App\Repositories\SubscriptionRepository;
use App\Transformers\SubscriptionTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
class SubscriptionController extends BaseController
{
use MakesHash;
protected $entity_type = Subscription::class;
protected $entity_transformer = SubscriptionTransformer::class;
@ -407,4 +410,72 @@ class SubscriptionController extends BaseController
return $this->itemResponse($subscription->fresh());
}
/**
* Perform bulk actions on the list view.
*
* @return Response
*
*
* @OA\Post(
* path="/api/v1/subscriptions/bulk",
* operationId="bulkSubscriptions",
* tags={"subscriptions"},
* summary="Performs bulk actions on an array of subscriptions",
* description="",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\RequestBody(
* description="User credentials",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="integer",
* description="Array of hashed IDs to be bulk 'actioned",
* example="[0,1,2,3]",
* ),
* )
* )
* ),
* @OA\Response(
* response=200,
* description="The Subscription response",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
$subscriptions = Subscription::withTrashed()->find($this->transformKeys($ids));
$subscriptions->each(function ($subscription, $key) use ($action) {
if (auth()->user()->can('edit', $subscription)) {
$this->subscription_repo->{$action}($subscription);
}
});
return $this->listResponse(Subscription::withTrashed()->whereIn('id', $this->transformKeys($ids)));
}
}

View File

@ -177,6 +177,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
// Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
Route::resource('subscriptions', 'SubscriptionController');
Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk');
Route::resource('cliente_subscriptions', 'ClientSubscriptionController');
});