added suspend & unsuspend api

This commit is contained in:
Bozhidar 2024-05-12 22:14:17 +03:00
parent d45a7829e6
commit 1f0ecd1011
2 changed files with 44 additions and 0 deletions

View file

@ -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',
]);
}
}
} }

View file

@ -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::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::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::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 // Domains
Route::get('domains', [\App\Http\Controllers\Api\DomainsController::class, 'index'])->name('api.domains.index'); Route::get('domains', [\App\Http\Controllers\Api\DomainsController::class, 'index'])->name('api.domains.index');