schneespur/app/Http/Controllers/Driver/DriverPhotoController.php
Michael 2c63440ed8 Revert: move code back to project root from schneespur/ subdirectory
- Reverts the schneespur/ subdirectory restructure (b8e426b)
- Restores package.json and vite.config.js (needed for npm build, were
  removed in an earlier cleanup before the restructure)
- Updates public/build/ assets with current Vite output (new content hashes)
2026-05-17 18:24:26 +00:00

45 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\Driver;
use App\Http\Controllers\Controller;
use App\Services\JobLifecycleService;
use App\Services\PhotoService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class DriverPhotoController extends Controller
{
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'photo' => ['required', 'image', 'mimes:jpeg,png,heic,webp', 'max:10240'],
'caption' => ['nullable', 'string', 'max:255'],
]);
$job = app(JobLifecycleService::class)->findActiveJob($request->user());
if (! $job) {
return response()->json(['message' => __('job.no_active_job')], 422);
}
if (! PhotoService::canAddPhoto($job)) {
return response()->json([
'message' => __('job.photo_limit_reached', ['max' => PhotoService::MAX_PHOTOS_PER_JOB]),
], 422);
}
$photo = app(PhotoService::class)->store($validated['photo'], $job);
if (! empty($validated['caption'])) {
$photo->update(['caption' => $validated['caption']]);
}
return response()->json([
'id' => $photo->id,
'thumbnail_url' => Storage::disk('public')->url($photo->thumbnail_path),
'photos_remaining' => PhotoService::MAX_PHOTOS_PER_JOB - $job->jobPhotos()->count(),
], 201);
}
}