schneespur/release/schneespur-1.0.2/app/Http/Controllers/Driver/DriverJobController.php
Michael 7288b93500 Release v1.0.2: diagnostic infrastructure core
Add neutral diagnostic framework for future reporting modules:
- DiagnosticReporterInterface, Registry, Manager, PayloadSanitizer
- Laravel exception hook in bootstrap/app.php
- Module permission declarations (requires_permissions in module.json)
- Core diagnostic report points (module boot/install/update failures)
- Module documentation update (moduldoku.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 16:54:11 +00:00

98 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Driver;
use App\Enums\JobType;
use App\Exceptions\JobLifecycleException;
use App\Http\Controllers\Controller;
use App\Models\CustomerObject;
use App\Models\Vehicle;
use App\Services\JobLifecycleService;
use App\Services\PhotoService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\Rule;
class DriverJobController extends Controller
{
public function start(Request $request): RedirectResponse
{
$validated = $request->validate([
'customer_object_id' => ['required', 'exists:customer_objects,id'],
'type' => ['required', Rule::enum(JobType::class)],
'vehicle_id' => ['nullable', 'exists:vehicles,id'],
]);
$customerObject = CustomerObject::findOrFail($validated['customer_object_id']);
$vehicle = isset($validated['vehicle_id']) ? Vehicle::find($validated['vehicle_id']) : null;
try {
app(JobLifecycleService::class)->startJob(
$request->user(),
$customerObject,
JobType::from($validated['type']),
$vehicle,
);
} catch (JobLifecycleException $e) {
return redirect()->back()->with('error', $e->getMessage());
}
return redirect()->back()->with('success', __('job.started'));
}
public function end(Request $request): RedirectResponse
{
$validated = $request->validate([
'notes' => ['nullable', 'string', 'max:1000'],
]);
try {
app(JobLifecycleService::class)->endJob(
$request->user(),
$validated['notes'] ?? null,
);
} catch (JobLifecycleException $e) {
return redirect()->back()->with('error', $e->getMessage());
}
return redirect()->back()->with('success', __('job.ended'));
}
public function active(Request $request): JsonResponse
{
$service = app(JobLifecycleService::class);
$user = $request->user();
$shift = $service->findActiveShift($user);
$job = $shift ? $service->findActiveJob($user) : null;
if ($job) {
$job->loadCount('gpsPoints')->load(['customerObject.customer', 'vehicle', 'jobPhotos']);
}
return response()->json([
'shift' => $shift ? [
'id' => $shift->id,
'started_at' => $shift->started_at->toIso8601String(),
] : null,
'job' => $job ? [
'id' => $job->id,
'customer_name' => $job->customerObject?->customer?->name ?? '',
'object_name' => $job->customerObject?->name,
'type_label' => $job->type->label(),
'vehicle_label' => $job->vehicle?->displayLabel(),
'started_at' => $job->started_at->toIso8601String(),
'gps_points_count' => $job->gps_points_count,
'photos_remaining' => PhotoService::MAX_PHOTOS_PER_JOB - $job->jobPhotos->count(),
'photos' => $job->jobPhotos->map(fn ($p) => [
'id' => $p->id,
'thumbnail_url' => Storage::disk('public')->url($p->thumbnail_path),
'full_url' => Storage::disk('public')->url($p->file_path),
'caption' => $p->caption,
]),
] : null,
]);
}
}