5 - Expose buffer multiplier in controller and resource API layer

This commit is contained in:
myrmidex 2026-03-20 00:37:23 +01:00
parent ad55a38c90
commit ed6be6249e
3 changed files with 20 additions and 4 deletions

View file

@ -33,6 +33,7 @@ public function store(Request $request, Scenario $scenario): JsonResponse
'type' => 'required|in:'.implode(',', BucketTypeEnum::values()),
'allocation_type' => 'required|in:'.implode(',', BucketAllocationTypeEnum::values()),
'allocation_value' => 'nullable|numeric',
'buffer_multiplier' => 'sometimes|nullable|numeric|min:0',
'priority' => 'nullable|integer|min:1',
]);
@ -52,7 +53,8 @@ public function store(Request $request, Scenario $scenario): JsonResponse
$allocationType,
$type,
$validated['allocation_value'] ?? null,
$validated['priority'] ?? null
$validated['priority'] ?? null,
isset($validated['buffer_multiplier']) ? (float) $validated['buffer_multiplier'] : null,
);
return response()->json([
@ -74,6 +76,7 @@ public function update(Request $request, Bucket $bucket): JsonResponse
'type' => 'required|in:'.implode(',', BucketTypeEnum::values()),
'allocation_type' => 'required|in:'.implode(',', BucketAllocationTypeEnum::values()),
'allocation_value' => 'nullable|numeric',
'buffer_multiplier' => 'sometimes|nullable|numeric|min:0',
'priority' => 'nullable|integer|min:1',
]);
@ -105,6 +108,11 @@ public function update(Request $request, Bucket $bucket): JsonResponse
$validated['allocation_value'] = null;
}
// Buffer only applies to fixed_limit buckets — always reset on type change
if ($allocationType !== BucketAllocationTypeEnum::FIXED_LIMIT) {
$validated['buffer_multiplier'] = 0.0;
}
// Handle priority change if needed
if (isset($validated['priority']) && $validated['priority'] !== $bucket->priority) {
$this->updateBucketPriority($bucket, $validated['priority']);
@ -221,7 +229,8 @@ private function formatBucketResponse(Bucket $bucket): array
'allocation_type' => $bucket->allocation_type,
'allocation_value' => $bucket->allocation_value,
'allocation_type_label' => $bucket->getAllocationTypeLabel(),
'formatted_allocation_value' => $bucket->getFormattedAllocationValue(),
'buffer_multiplier' => (float) $bucket->buffer_multiplier,
'effective_capacity' => $bucket->getEffectiveCapacity(),
'current_balance' => $bucket->getCurrentBalance(),
'has_available_space' => $bucket->hasAvailableSpace(),
'available_space' => $bucket->getAvailableSpace(),

View file

@ -19,7 +19,8 @@ public function toArray(Request $request): array
'allocation_type' => $this->allocation_type,
'allocation_value' => $this->allocation_value,
'allocation_type_label' => $this->getAllocationTypeLabel(),
'formatted_allocation_value' => $this->getFormattedAllocationValue(),
'buffer_multiplier' => (float) $this->buffer_multiplier,
'effective_capacity' => $this->getEffectiveCapacity(),
'current_balance' => $this->getCurrentBalance(),
'has_available_space' => $this->hasAvailableSpace(),
'available_space' => $this->getAvailableSpace(),

View file

@ -175,7 +175,13 @@ parameters:
path: app/Http/Resources/BucketResource.php
-
message: '#^Call to an undefined method App\\Http\\Resources\\BucketResource\:\:getFormattedAllocationValue\(\)\.$#'
message: '#^Access to an undefined property App\\Http\\Resources\\BucketResource\:\:\$buffer_multiplier\.$#'
identifier: property.notFound
count: 1
path: app/Http/Resources/BucketResource.php
-
message: '#^Call to an undefined method App\\Http\\Resources\\BucketResource\:\:getEffectiveCapacity\(\)\.$#'
identifier: method.notFound
count: 1
path: app/Http/Resources/BucketResource.php