24 - Remove multi-scenario scaffolding
Some checks failed
CI / ci (push) Failing after 10m48s
CI / ci (pull_request) Failing after 10m4s

This commit is contained in:
myrmidex 2026-03-30 00:01:05 +02:00
parent afc65b4f3a
commit cf6f0c76c2
6 changed files with 1 additions and 282 deletions

View file

@ -1,13 +0,0 @@
<?php
namespace App\Actions;
use App\Models\Scenario;
readonly class DeleteScenarioAction
{
public function execute(Scenario $scenario): void
{
$scenario->delete();
}
}

View file

@ -2,36 +2,21 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Actions\CreateScenarioAction;
use App\Actions\DeleteScenarioAction;
use App\Actions\UpdateScenarioAction; use App\Actions\UpdateScenarioAction;
use App\Http\Requests\StoreScenarioRequest;
use App\Http\Requests\UpdateScenarioRequest; use App\Http\Requests\UpdateScenarioRequest;
use App\Http\Resources\BucketResource; use App\Http\Resources\BucketResource;
use App\Http\Resources\ScenarioResource; use App\Http\Resources\ScenarioResource;
use App\Models\Scenario; use App\Models\Scenario;
use App\Repositories\ScenarioRepository;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia; use Inertia\Inertia;
use Inertia\Response; use Inertia\Response;
class ScenarioController extends Controller class ScenarioController extends Controller
{ {
public function __construct( public function __construct(
private readonly ScenarioRepository $scenarioRepository,
private readonly CreateScenarioAction $createScenarioAction,
private readonly UpdateScenarioAction $updateScenarioAction, private readonly UpdateScenarioAction $updateScenarioAction,
private readonly DeleteScenarioAction $deleteScenarioAction,
) {} ) {}
public function index(): Response
{
return Inertia::render('Scenarios/Index', [
'scenarios' => ScenarioResource::collection($this->scenarioRepository->getAll()),
]);
}
public function show(Scenario $scenario): Response public function show(Scenario $scenario): Response
{ {
$scenario->load(['buckets' => function ($query) { $scenario->load(['buckets' => function ($query) {
@ -44,38 +29,10 @@ public function show(Scenario $scenario): Response
]); ]);
} }
public function create(): Response
{
return Inertia::render('Scenarios/Create');
}
public function store(StoreScenarioRequest $request): RedirectResponse
{
$scenario = $this->createScenarioAction->execute($request->validated());
return redirect()->route('scenarios.show', $scenario);
}
public function edit(Scenario $scenario): Response
{
return Inertia::render('Scenarios/Edit', [
'scenario' => ScenarioResource::make($scenario)->resolve(),
]);
}
public function update(UpdateScenarioRequest $request, Scenario $scenario): JsonResponse public function update(UpdateScenarioRequest $request, Scenario $scenario): JsonResponse
{ {
$this->updateScenarioAction->execute($scenario, $request->validated()); $this->updateScenarioAction->execute($scenario, $request->validated());
return response()->json(['success' => true]); return response()->json(['success' => true]);
} }
public function destroy(Scenario $scenario): RedirectResponse
{
$this->deleteScenarioAction->execute($scenario);
return redirect()
->route('scenarios.index')
->with('success', 'Scenario deleted successfully');
}
} }

View file

@ -1,42 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreScenarioRequest extends FormRequest
{
public function authorize(): bool
{
// In production, check if user is authenticated
// For now, allow all requests
return true;
}
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255', 'min:1'],
'description' => ['nullable', 'string', 'max:1000'],
];
}
public function messages(): array
{
return [
'name.required' => 'A scenario name is required.',
'name.min' => 'The scenario name must be at least 1 character.',
'name.max' => 'The scenario name cannot exceed 255 characters.',
];
}
protected function prepareForValidation(): void
{
// Trim the name
if ($this->has('name')) {
$this->merge([
'name' => trim($this->name),
]);
}
}
}

View file

@ -1,16 +0,0 @@
<?php
namespace App\Repositories;
use App\Models\Scenario;
use Illuminate\Support\Collection;
class ScenarioRepository
{
public function getAll(): Collection
{
return Scenario::query()
->orderBy('created_at', 'desc')
->get();
}
}

View file

@ -1,153 +0,0 @@
import { Head, router } from '@inertiajs/react';
import React, { useState } from 'react';
interface Scenario {
id: string;
name: string;
created_at: string;
updated_at: string;
}
interface Props {
scenarios: {
data: Scenario[];
};
}
export default function Index({ scenarios }: Props) {
const [showCreateForm, setShowCreateForm] = useState(false);
const [name, setName] = useState('');
const [errors, setErrors] = useState<{ name?: string }>({});
const handleCreateScenario = (e: React.FormEvent) => {
e.preventDefault();
router.post('/scenarios', { name }, {
onSuccess: () => {
setShowCreateForm(false);
setName('');
setErrors({});
},
onError: (errors) => {
setErrors(errors);
}
});
};
const handleCancel = () => {
setShowCreateForm(false);
setName('');
setErrors({});
};
return (
<>
<Head title="Budget Scenarios" />
<div className="min-h-screen bg-gray-50 py-8">
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div className="mb-8">
<h1 className="text-3xl font-bold text-gray-900">Budget Scenarios</h1>
<p className="mt-2 text-gray-600">
Manage your budget projections with water-themed scenarios
</p>
</div>
{/* Create Scenario Form */}
{showCreateForm && (
<div className="mb-8 rounded-lg bg-white p-6 shadow" data-testid="scenario-form">
<h2 className="text-xl font-semibold text-gray-900 mb-4">Create New Scenario</h2>
<form onSubmit={handleCreateScenario}>
<div className="mb-4">
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
Scenario Name
</label>
<input
type="text"
id="name"
data-testid="scenario-name"
value={name}
onChange={(e) => setName(e.target.value)}
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm text-gray-900 focus:border-blue-500 focus:outline-none focus:ring-blue-500"
placeholder="e.g., 2025 Budget"
/>
{errors.name && (
<p className="mt-1 text-sm text-red-600">{errors.name}</p>
)}
</div>
<div className="flex gap-3">
<button
type="submit"
data-testid="save-scenario"
className="rounded-md bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
>
Create Scenario
</button>
<button
type="button"
data-testid="cancel-scenario"
onClick={handleCancel}
className="rounded-md border border-gray-300 px-4 py-2 text-sm font-semibold text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2"
>
Cancel
</button>
</div>
</form>
</div>
)}
{/* Create Button */}
{!showCreateForm && (
<div className="mb-8">
<button
onClick={() => setShowCreateForm(true)}
data-testid="create-scenario-button"
className="rounded-md bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
>
+ New Scenario
</button>
</div>
)}
{/* Scenarios List */}
{scenarios.data.length === 0 ? (
<div className="rounded-lg bg-white p-12 text-center shadow">
<div className="mx-auto h-12 w-12 text-gray-400">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
</div>
<h3 className="mt-4 text-lg font-semibold text-gray-900">No scenarios yet</h3>
<p className="mt-2 text-gray-600">
Create your first budget scenario to get started
</p>
</div>
) : (
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{scenarios.data.map((scenario) => (
<div
key={scenario.id}
onClick={() => router.visit(`/scenarios/${scenario.id}`)}
className="cursor-pointer rounded-lg bg-white p-6 shadow transition-shadow hover:shadow-lg"
>
<h3 className="text-lg font-semibold text-gray-900">
{scenario.name}
</h3>
<p className="mt-2 text-sm text-gray-600">
Created {new Date(scenario.created_at).toLocaleDateString()}
</p>
<div className="mt-4 flex items-center text-sm text-blue-600">
View Details
<svg className="ml-2 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
</div>
</div>
))}
</div>
)}
</div>
</div>
</>
);
}

View file

@ -7,20 +7,13 @@
use App\Models\Scenario; use App\Models\Scenario;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
// Single-scenario MVP: redirect root to the default scenario // Single scenario: redirect to default
Route::get('/', function () { Route::get('/', function () {
return redirect()->route('scenarios.show', Scenario::firstOrFail()); return redirect()->route('scenarios.show', Scenario::firstOrFail());
})->name('home'); })->name('home');
Route::get('/scenarios/{scenario}', [ScenarioController::class, 'show'])->name('scenarios.show'); Route::get('/scenarios/{scenario}', [ScenarioController::class, 'show'])->name('scenarios.show');
// Scenario CRUD routes (hidden for single-scenario MVP, re-enable later)
// Route::get('/scenarios', [ScenarioController::class, 'index'])->name('scenarios.index');
// Route::get('/scenarios/create', [ScenarioController::class, 'create'])->name('scenarios.create');
// Route::post('/scenarios', [ScenarioController::class, 'store'])->name('scenarios.store');
// Route::get('/scenarios/{scenario}/edit', [ScenarioController::class, 'edit'])->name('scenarios.edit');
Route::patch('/scenarios/{scenario}', [ScenarioController::class, 'update'])->name('scenarios.update'); Route::patch('/scenarios/{scenario}', [ScenarioController::class, 'update'])->name('scenarios.update');
// Route::delete('/scenarios/{scenario}', [ScenarioController::class, 'destroy'])->name('scenarios.destroy');
// Bucket routes (no auth required for MVP) // Bucket routes (no auth required for MVP)
Route::get('/scenarios/{scenario}/buckets', [BucketController::class, 'index'])->name('buckets.index'); Route::get('/scenarios/{scenario}/buckets', [BucketController::class, 'index'])->name('buckets.index');
@ -41,11 +34,4 @@
Route::post('/scenarios/{scenario}/projections/preview', [ProjectionController::class, 'preview'])->name('projections.preview'); Route::post('/scenarios/{scenario}/projections/preview', [ProjectionController::class, 'preview'])->name('projections.preview');
Route::post('/scenarios/{scenario}/projections/apply', [ProjectionController::class, 'apply'])->name('projections.apply'); Route::post('/scenarios/{scenario}/projections/apply', [ProjectionController::class, 'apply'])->name('projections.apply');
// Auth dashboard (hidden for single-scenario MVP, re-enable later)
// Route::middleware(['auth', 'verified'])->group(function () {
// Route::get('dashboard', function () {
// return Inertia::render('dashboard');
// })->name('dashboard');
// });
require __DIR__.'/settings.php'; require __DIR__.'/settings.php';