-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #88 add the quotas page, ensure quotas for deployments
- Loading branch information
1 parent
1e75e6c
commit dce31ac
Showing
19 changed files
with
616 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Actions\Services; | ||
|
||
use App\Models\DeploymentData; | ||
use App\Models\Service; | ||
use App\Models\Team; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\DB; | ||
use Lorisleiva\Actions\ActionRequest; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class CreateService | ||
{ | ||
use AsAction; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'name' => ['required', 'string', 'max:255'], | ||
'deploymentData' => ['required', 'array'], | ||
]; | ||
} | ||
|
||
public function authorize(ActionRequest $request): bool | ||
{ | ||
return true; // Authorization will be handled by policies | ||
} | ||
|
||
public function handle(User $user, Team $team, string $name, DeploymentData $deploymentData): Service | ||
{ | ||
return DB::transaction(function () use ($user, $team, $name, $deploymentData) { | ||
$swarm = $team->swarms()->firstOrFail(); | ||
|
||
$service = new Service([ | ||
'name' => $name, | ||
'team_id' => $team->id, | ||
'swarm_id' => $swarm->id, | ||
]); | ||
|
||
$service->save(); | ||
|
||
StartDeployment::run($user, $service, $deploymentData); | ||
|
||
return $service; | ||
}); | ||
} | ||
|
||
public function asController(ActionRequest $request) | ||
{ | ||
$user = $request->user(); | ||
$team = $user->currentTeam; | ||
$quotas = $team->quotas(); | ||
|
||
$quotas->services->ensureQuota(); | ||
|
||
$validated = $request->validated(); | ||
$deploymentData = DeploymentData::validateAndCreate($validated['deploymentData']); | ||
|
||
$service = $this->handle($user, $team, $validated['name'], $deploymentData); | ||
|
||
return redirect()->route('services.deployments', $service) | ||
->with('success', 'Service created and deployment scheduled successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Team; | ||
use Inertia\Inertia; | ||
|
||
class TeamQuotasController extends Controller | ||
{ | ||
public function index(Team $team) | ||
{ | ||
$quotas = $team->quotas(); | ||
$isOnTrial = $team->onTrial(); | ||
$quotaReached = false; | ||
|
||
$formattedQuotas = []; | ||
foreach ($quotas as $key => $quota) { | ||
$formattedQuotas[$key] = [ | ||
'currentUsage' => $quota->currentUsage(), | ||
'maxUsage' => $quota->maxUsage, | ||
'isSoftQuota' => $quota->isSoftQuota, | ||
'almostQuotaReached' => $quota->almostQuotaReached(), | ||
'isIntrinsic' => $key === 'swarms', // Mark swarms as intrinsic | ||
]; | ||
|
||
if ($quota->quotaReached() && ! $formattedQuotas[$key]['isIntrinsic']) { | ||
$quotaReached = true; | ||
} | ||
} | ||
|
||
return Inertia::render('Teams/Quotas', [ | ||
'team' => $team->only(['id', 'name']), | ||
'quotas' => $formattedQuotas, | ||
'isOnTrial' => $isOnTrial, | ||
'quotaReached' => $quotaReached, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Models\PricingPlan; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
class Plan extends Data | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public int $price, | ||
public string $description, | ||
public ?string $product_id, | ||
public ?string $price_id, | ||
public array $quotas | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.