feat(subscription): add resource quota management for subscription plans and update related components
This commit is contained in:
@@ -130,6 +130,31 @@ class SubscriptionController extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* سقف منابع فقط `-1` (نامحدود) یا عددی مثبت است.
|
||||
*
|
||||
* `0` پلنی میساخت که هیچ منبعی نمیدهد و هر مقدار منفیِ دیگری هم مثل `-1` رفتار
|
||||
* میکرد بیآنکه چیزی در پنل نشانش بدهد — هر دو خاموش و گیجکنندهاند.
|
||||
*/
|
||||
private function rejectInvalidResourceLimit(array $data): ?JsonResponse
|
||||
{
|
||||
if (!isset($data['max_resources'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$max = (int) $data['max_resources'];
|
||||
|
||||
if ($max === 0 || $max < SubscriptionPlan::UNLIMITED) {
|
||||
return $this->error(
|
||||
ErrorCodes::ERR_VALIDATION_001,
|
||||
'max_resources باید عددی مثبت باشد یا -1 برای نامحدود',
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#[Route('/api/v1/admin/subscription/plan', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function adminCreatePlan(Request $request): JsonResponse
|
||||
@@ -145,6 +170,10 @@ class SubscriptionController extends BaseController
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'پلنی با این نام از قبل وجود دارد', 422);
|
||||
}
|
||||
|
||||
if (($error = $this->rejectInvalidResourceLimit($data)) !== null) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$plan = new SubscriptionPlan(
|
||||
$name,
|
||||
(int) $data['level'],
|
||||
@@ -169,6 +198,10 @@ class SubscriptionController extends BaseController
|
||||
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
|
||||
if (($error = $this->rejectInvalidResourceLimit($data)) !== null) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if (isset($data['name'])) {
|
||||
$existing = $this->planRepo->findByName(trim($data['name']));
|
||||
if ($existing !== null && $existing->getUuid() !== $plan->getUuid()) {
|
||||
|
||||
Reference in New Issue
Block a user