Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Admin/DomainsController.php
Show All 14 Lines | class DomainsController extends \App\Http\Controllers\API\V4\DomainsController | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$search = trim(request()->input('search')); | $search = trim(request()->input('search')); | ||||
$owner = trim(request()->input('owner')); | $owner = trim(request()->input('owner')); | ||||
$result = collect([]); | $result = collect([]); | ||||
if ($owner) { | if ($owner) { | ||||
if ($owner = User::withEnvTenant()->find($owner)) { | if ($owner = User::find($owner)) { | ||||
foreach ($owner->wallets as $wallet) { | foreach ($owner->wallets as $wallet) { | ||||
$entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | $entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | ||||
foreach ($entitlements as $entitlement) { | foreach ($entitlements as $entitlement) { | ||||
$domain = $entitlement->entitleable; | $domain = $entitlement->entitleable; | ||||
$result->push($domain); | $result->push($domain); | ||||
} | } | ||||
} | } | ||||
$result = $result->sortBy('namespace')->values(); | $result = $result->sortBy('namespace')->values(); | ||||
} | } | ||||
} elseif (!empty($search)) { | } elseif (!empty($search)) { | ||||
if ($domain = Domain::withEnvTenant()->where('namespace', $search)->first()) { | if ($domain = Domain::where('namespace', $search)->first()) { | ||||
$result->push($domain); | $result->push($domain); | ||||
} | } | ||||
} | } | ||||
// Process the result | // Process the result | ||||
$result = $result->map(function ($domain) { | $result = $result->map(function ($domain) { | ||||
$data = $domain->toArray(); | $data = $domain->toArray(); | ||||
$data = array_merge($data, self::domainStatuses($domain)); | $data = array_merge($data, self::domainStatuses($domain)); | ||||
Show All 14 Lines | class DomainsController extends \App\Http\Controllers\API\V4\DomainsController | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* @param string $id Domain identifier | * @param string $id Domain identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse The response | * @return \Illuminate\Http\JsonResponse The response | ||||
*/ | */ | ||||
public function suspend(Request $request, $id) | public function suspend(Request $request, $id) | ||||
{ | { | ||||
$domain = Domain::withEnvTenant()->find($id); | $domain = Domain::find($id); | ||||
if (empty($domain) || $domain->isPublic()) { | if (empty($domain) || $domain->isPublic()) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
$domain->suspend(); | $domain->suspend(); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('app.domain-suspend-success'), | 'message' => __('app.domain-suspend-success'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Un-Suspend the domain | * Un-Suspend the domain | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* @param string $id Domain identifier | * @param string $id Domain identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse The response | * @return \Illuminate\Http\JsonResponse The response | ||||
*/ | */ | ||||
public function unsuspend(Request $request, $id) | public function unsuspend(Request $request, $id) | ||||
{ | { | ||||
$domain = Domain::withEnvTenant()->find($id); | $domain = Domain::find($id); | ||||
if (empty($domain) || $domain->isPublic()) { | if (empty($domain) || $domain->isPublic()) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
$domain->unsuspend(); | $domain->unsuspend(); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('app.domain-unsuspend-success'), | 'message' => __('app.domain-unsuspend-success'), | ||||
]); | ]); | ||||
} | } | ||||
} | } |