2023-06-07 13:08:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Environment;
|
|
|
|
use App\Models\Project;
|
|
|
|
use App\Models\Server;
|
2023-06-16 13:01:58 +00:00
|
|
|
use App\Models\Team;
|
2023-06-07 13:08:35 +00:00
|
|
|
|
|
|
|
class MagicController extends Controller
|
|
|
|
{
|
|
|
|
public function servers()
|
|
|
|
{
|
|
|
|
return response()->json([
|
2023-07-14 11:38:24 +00:00
|
|
|
'servers' => Server::isUsable()->get()
|
2023-06-07 13:08:35 +00:00
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-07 13:08:35 +00:00
|
|
|
public function destinations()
|
|
|
|
{
|
|
|
|
return response()->json([
|
|
|
|
'destinations' => Server::destinationsByServer(request()->query('server_id'))->sortBy('name')
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-07 13:08:35 +00:00
|
|
|
public function projects()
|
|
|
|
{
|
|
|
|
return response()->json([
|
|
|
|
'projects' => Project::ownedByCurrentTeam()->get()
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-07 13:08:35 +00:00
|
|
|
public function environments()
|
|
|
|
{
|
|
|
|
return response()->json([
|
|
|
|
'environments' => Project::ownedByCurrentTeam()->whereUuid(request()->query('project_uuid'))->first()->environments
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-15 07:15:41 +00:00
|
|
|
public function newProject()
|
2023-06-07 13:08:35 +00:00
|
|
|
{
|
|
|
|
$project = Project::firstOrCreate(
|
|
|
|
['name' => request()->query('name') ?? generate_random_name()],
|
|
|
|
['team_id' => session('currentTeam')->id]
|
|
|
|
);
|
|
|
|
return response()->json([
|
|
|
|
'project_uuid' => $project->uuid
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-15 07:15:41 +00:00
|
|
|
public function newEnvironment()
|
2023-06-07 13:08:35 +00:00
|
|
|
{
|
|
|
|
$environment = Environment::firstOrCreate(
|
|
|
|
['name' => request()->query('name') ?? generate_random_name()],
|
|
|
|
['project_id' => Project::ownedByCurrentTeam()->whereUuid(request()->query('project_uuid'))->firstOrFail()->id]
|
|
|
|
);
|
|
|
|
return response()->json([
|
|
|
|
'environment_name' => $environment->name,
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-16 13:01:58 +00:00
|
|
|
public function newTeam()
|
|
|
|
{
|
|
|
|
$team = Team::create(
|
|
|
|
[
|
|
|
|
'name' => request()->query('name') ?? generate_random_name(),
|
|
|
|
'personal_team' => false,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
auth()->user()->teams()->attach($team, ['role' => 'admin']);
|
|
|
|
session(['currentTeam' => $team]);
|
|
|
|
return redirect(request()->header('Referer'));
|
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
}
|