17 - Add distribution_mode to Scenario
This commit is contained in:
parent
cf89ee7cd2
commit
f14057d6d9
7 changed files with 59 additions and 0 deletions
30
app/Enums/DistributionModeEnum.php
Normal file
30
app/Enums/DistributionModeEnum.php
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum DistributionModeEnum: string
|
||||||
|
{
|
||||||
|
case EVEN = 'even';
|
||||||
|
case PRIORITY = 'priority';
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::EVEN => 'Even Split',
|
||||||
|
self::PRIORITY => 'Priority Order',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::EVEN => 'Split evenly across buckets in each phase, respecting individual capacity',
|
||||||
|
self::PRIORITY => 'Fill highest-priority bucket first, then next',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,8 @@ public function toArray(Request $request): array
|
||||||
'id' => $this->uuid,
|
'id' => $this->uuid,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
|
'distribution_mode' => $this->distribution_mode->value,
|
||||||
|
'distribution_mode_label' => $this->distribution_mode->getLabel(),
|
||||||
'created_at' => $this->created_at,
|
'created_at' => $this->created_at,
|
||||||
'updated_at' => $this->updated_at,
|
'updated_at' => $this->updated_at,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\DistributionModeEnum;
|
||||||
use App\Models\Traits\HasUuid;
|
use App\Models\Traits\HasUuid;
|
||||||
use Database\Factories\ScenarioFactory;
|
use Database\Factories\ScenarioFactory;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
@ -12,6 +13,7 @@
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $uuid
|
* @property string $uuid
|
||||||
|
* @property DistributionModeEnum $distribution_mode
|
||||||
* @property Collection<Bucket> $buckets
|
* @property Collection<Bucket> $buckets
|
||||||
*
|
*
|
||||||
* @method static create(array $data)
|
* @method static create(array $data)
|
||||||
|
|
@ -24,8 +26,16 @@ class Scenario extends Model
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
|
'distribution_mode',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'distribution_mode' => DistributionModeEnum::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function buckets(): HasMany
|
public function buckets(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Bucket::class);
|
return $this->hasMany(Bucket::class);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Enums\DistributionModeEnum;
|
||||||
use App\Models\Scenario;
|
use App\Models\Scenario;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
|
@ -15,6 +16,12 @@ public function definition(): array
|
||||||
return [
|
return [
|
||||||
'name' => $this->faker->words(2, true).' Budget',
|
'name' => $this->faker->words(2, true).' Budget',
|
||||||
'description' => $this->faker->text,
|
'description' => $this->faker->text,
|
||||||
|
'distribution_mode' => DistributionModeEnum::EVEN,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function priority(): static
|
||||||
|
{
|
||||||
|
return $this->state(fn () => ['distribution_mode' => DistributionModeEnum::PRIORITY]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\DistributionModeEnum;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
@ -13,6 +14,7 @@ public function up(): void
|
||||||
$table->uuid('uuid')->unique();
|
$table->uuid('uuid')->unique();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->text('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
|
$table->string('distribution_mode')->default(DistributionModeEnum::EVEN->value);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,12 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: app/Http/Resources/OutflowResource.php
|
path: app/Http/Resources/OutflowResource.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: '#^Access to an undefined property App\\Http\\Resources\\ScenarioResource\:\:\$distribution_mode\.$#'
|
||||||
|
identifier: property.notFound
|
||||||
|
count: 2
|
||||||
|
path: app/Http/Resources/ScenarioResource.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: '#^Access to an undefined property App\\Http\\Resources\\ScenarioResource\:\:\$created_at\.$#'
|
message: '#^Access to an undefined property App\\Http\\Resources\\ScenarioResource\:\:\$created_at\.$#'
|
||||||
identifier: property.notFound
|
identifier: property.notFound
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import IncomeDistributionPreview from '@/components/IncomeDistributionPreview';
|
||||||
interface Scenario {
|
interface Scenario {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
distribution_mode: 'even' | 'priority';
|
||||||
|
distribution_mode_label: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue