initial commit
This commit is contained in:
129
app/Http/Controllers/EventController.php
Normal file
129
app/Http/Controllers/EventController.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$events = Event::with('client')->orderBy('start_time')->get();
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
|
||||
// Format for FullCalendar
|
||||
$calendarEvents = $events->map(fn (Event $e) => [
|
||||
'id' => $e->id,
|
||||
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
|
||||
'start' => $e->start_time->toIso8601String(),
|
||||
'end' => $e->end_time?->toIso8601String(),
|
||||
'backgroundColor' => $e->color,
|
||||
'borderColor' => $e->color,
|
||||
'extendedProps' => [
|
||||
'status' => $e->status->value,
|
||||
'client' => $e->client?->name,
|
||||
'type' => $e->event_type,
|
||||
'priority' => $e->is_priority,
|
||||
],
|
||||
]);
|
||||
|
||||
return view('schedule.index', compact('events', 'clients', 'calendarEvents'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'event_type' => 'required|in:task,meeting,deadline,posting',
|
||||
'start_time' => 'required|date',
|
||||
'end_time' => 'nullable|date|after:start_time',
|
||||
'location' => 'nullable|string|max:255',
|
||||
'is_priority' => 'boolean',
|
||||
'is_all_day' => 'boolean',
|
||||
'color' => 'nullable|string|max:20',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['is_priority'] = $request->boolean('is_priority');
|
||||
$validated['is_all_day'] = $request->boolean('is_all_day');
|
||||
|
||||
Event::create($validated);
|
||||
|
||||
return redirect()->route('schedule.index')
|
||||
->with('success', '🐾 Event scheduled!');
|
||||
}
|
||||
|
||||
public function update(Request $request, Event $event): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'event_type' => 'required|in:task,meeting,deadline,posting',
|
||||
'start_time' => 'required|date',
|
||||
'end_time' => 'nullable|date',
|
||||
'location' => 'nullable|string|max:255',
|
||||
'is_priority' => 'boolean',
|
||||
'status' => 'required|in:pending,in_progress,completed,cancelled',
|
||||
'color' => 'nullable|string|max:20',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['is_priority'] = $request->boolean('is_priority');
|
||||
$event->update($validated);
|
||||
|
||||
return redirect()->route('schedule.index')
|
||||
->with('success', '🐾 Event updated!');
|
||||
}
|
||||
|
||||
public function updateDates(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'start_time' => 'required|date',
|
||||
'end_time' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$event->update($validated);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function destroy(Event $event): RedirectResponse
|
||||
{
|
||||
$event->delete();
|
||||
|
||||
return redirect()->route('schedule.index')
|
||||
->with('success', '🐾 Event removed.');
|
||||
}
|
||||
|
||||
public function apiList(): JsonResponse
|
||||
{
|
||||
$events = Event::with('client')->get()->map(fn (Event $e) => [
|
||||
'id' => $e->id,
|
||||
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
|
||||
'start' => $e->start_time->toIso8601String(),
|
||||
'end' => $e->end_time?->toIso8601String(),
|
||||
'backgroundColor' => $e->color,
|
||||
'borderColor' => $e->color,
|
||||
'allDay' => $e->is_all_day,
|
||||
'extendedProps' => [
|
||||
'status' => $e->status->value,
|
||||
'client' => $e->client?->name,
|
||||
'type' => $e->event_type,
|
||||
'priority' => $e->is_priority,
|
||||
],
|
||||
]);
|
||||
|
||||
return response()->json($events);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user