2025-07-12 18:09:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
2026-05-02 17:10:00 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2025-07-12 18:09:11 +02:00
|
|
|
namespace App\Http\Controllers\Milestones;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2026-05-02 17:10:00 +02:00
|
|
|
use App\Models\User;
|
2025-07-12 18:09:11 +02:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2026-05-02 09:52:42 +02:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
2025-07-12 18:09:11 +02:00
|
|
|
|
|
|
|
|
class MilestoneController extends Controller
|
|
|
|
|
{
|
2025-07-13 00:18:45 +02:00
|
|
|
public function store(Request $request): RedirectResponse
|
2025-07-12 18:09:11 +02:00
|
|
|
{
|
2026-05-02 16:14:31 +02:00
|
|
|
$validated = $request->validate([
|
2025-07-12 18:09:11 +02:00
|
|
|
'target' => 'required|integer|min:1',
|
|
|
|
|
'description' => 'required|string|max:255',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-05-02 17:10:00 +02:00
|
|
|
$tracker = User::default()->tracker;
|
|
|
|
|
|
|
|
|
|
if (! $tracker) {
|
|
|
|
|
return back()->withErrors(['tracker' => 'No tracker found. Please complete onboarding first.']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tracker->milestones()->create($validated);
|
2025-07-13 00:18:45 +02:00
|
|
|
|
|
|
|
|
return back()->with('success', 'Milestone created successfully');
|
2025-07-12 18:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index(): JsonResponse
|
|
|
|
|
{
|
2026-05-02 17:10:00 +02:00
|
|
|
$tracker = User::default()->tracker;
|
|
|
|
|
|
|
|
|
|
if (! $tracker) {
|
|
|
|
|
return response()->json([]);
|
|
|
|
|
}
|
2025-07-13 00:18:45 +02:00
|
|
|
|
2026-05-02 17:10:00 +02:00
|
|
|
return response()->json($tracker->milestones()->orderBy('target')->get());
|
2025-07-12 18:09:11 +02:00
|
|
|
}
|
2026-05-02 09:52:42 +02:00
|
|
|
}
|