From 1f0ecd101117ad50068626ec84b135359d6ff114 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Sun, 12 May 2024 22:14:17 +0300 Subject: [PATCH] added suspend & unsuspend api --- .../Api/HostingSubscriptionsController.php | 42 +++++++++++++++++++ web/routes/api.php | 2 + 2 files changed, 44 insertions(+) diff --git a/web/app/Http/Controllers/Api/HostingSubscriptionsController.php b/web/app/Http/Controllers/Api/HostingSubscriptionsController.php index 6b197f1..7267ac9 100644 --- a/web/app/Http/Controllers/Api/HostingSubscriptionsController.php +++ b/web/app/Http/Controllers/Api/HostingSubscriptionsController.php @@ -110,4 +110,46 @@ class HostingSubscriptionsController extends ApiController } } + + public function suspend($id) + { + $findHostingSubscription = HostingSubscription::where('id', $id)->first(); + if ($findHostingSubscription) { + + $findDomains = Domain::where('hosting_subscription_id', $findHostingSubscription->id)->get(); + if ($findDomains->count() > 0) { + foreach ($findDomains as $domain) { + $domain->status = Domain::STATUS_SUSPENDED; + $domain->save(); + } + } + + return response()->json([ + 'status' => 'ok', + 'message' => 'Hosting subscription suspended', + ]); + } + + } + + public function unsuspend($id) + { + $findHostingSubscription = HostingSubscription::where('id', $id)->first(); + if ($findHostingSubscription) { + + $findDomains = Domain::where('hosting_subscription_id', $findHostingSubscription->id)->get(); + if ($findDomains->count() > 0) { + foreach ($findDomains as $domain) { + $domain->status = Domain::STATUS_ACTIVE; + $domain->save(); + } + } + + return response()->json([ + 'status' => 'ok', + 'message' => 'Hosting subscription unsuspended', + ]); + } + + } } diff --git a/web/routes/api.php b/web/routes/api.php index 659d198..1ae4d89 100644 --- a/web/routes/api.php +++ b/web/routes/api.php @@ -31,6 +31,8 @@ Route::middleware(\App\Http\Middleware\ApiKeyMiddleware::class)->group(function( Route::post('hosting-subscriptions', [\App\Http\Controllers\Api\HostingSubscriptionsController::class, 'store'])->name('api.hosting-subscriptions.store'); Route::put('hosting-subscriptions/{id}', [\App\Http\Controllers\Api\HostingSubscriptionsController::class, 'update'])->name('api.hosting-subscriptions.update'); Route::delete('hosting-subscriptions/{id}', [\App\Http\Controllers\Api\HostingSubscriptionsController::class, 'destroy'])->name('api.hosting-subscriptions.destroy'); + Route::post('hosting-subscriptions/{id}/suspend', [\App\Http\Controllers\Api\HostingSubscriptionsController::class, 'suspend'])->name('api.hosting-subscriptions.suspend'); + Route::post('hosting-subscriptions/{id}/unsuspend', [\App\Http\Controllers\Api\HostingSubscriptionsController::class, 'unsuspend'])->name('api.hosting-subscriptions.unsuspend'); // Domains Route::get('domains', [\App\Http\Controllers\Api\DomainsController::class, 'index'])->name('api.domains.index');