diff --git a/app/Http/Controllers/Api/Tenant/PhotoController.php b/app/Http/Controllers/Api/Tenant/PhotoController.php index 2c20d61..5176941 100644 --- a/app/Http/Controllers/Api/Tenant/PhotoController.php +++ b/app/Http/Controllers/Api/Tenant/PhotoController.php @@ -60,19 +60,44 @@ class PhotoController extends Controller : null; $query = Photo::where('event_id', $event->id) - ->with('event')->withCount('likes') - ->orderBy('created_at', 'desc'); + ->with('event')->withCount('likes'); // Filters if ($request->has('status')) { $query->where('status', $request->status); } + if ($request->boolean('featured')) { + $query->where('is_featured', true); + } + if ($request->has('user_id')) { $query->where('uploader_id', $request->user_id); } - $perPage = $request->get('per_page', 20); + if ($request->filled('ingest_source')) { + $query->where('ingest_source', $request->string('ingest_source')); + } + + $visibility = strtolower((string) $request->input('visibility', '')); + if ($visibility === 'visible') { + $query->where('status', '!=', 'hidden'); + } elseif ($visibility === 'hidden') { + $query->where('status', 'hidden'); + } + + if ($request->filled('search')) { + $term = strtolower(trim((string) $request->get('search'))); + $query->where(function ($inner) use ($term) { + $inner->whereRaw('LOWER(original_name) LIKE ?', ['%'.$term.'%']) + ->orWhereRaw('LOWER(filename) LIKE ?', ['%'.$term.'%']); + }); + } + + $direction = strtolower($request->get('sort', 'desc')) === 'asc' ? 'asc' : 'desc'; + $query->orderBy('created_at', $direction); + + $perPage = max(1, min((int) $request->get('per_page', 40), 100)); $photos = $query->paginate($perPage); return PhotoResource::collection($photos)->additional([ @@ -80,6 +105,37 @@ class PhotoController extends Controller ]); } + public function visibility(Request $request, string $eventSlug, Photo $photo): JsonResponse + { + $tenantId = $request->attributes->get('tenant_id'); + $event = Event::where('slug', $eventSlug) + ->where('tenant_id', $tenantId) + ->firstOrFail(); + + if ($photo->event_id !== $event->id) { + return ApiError::response( + 'photo_not_found', + 'Foto nicht gefunden', + 'Das Foto gehört nicht zu diesem Event.', + Response::HTTP_NOT_FOUND, + ['photo_id' => $photo->id] + ); + } + + $validated = $request->validate([ + 'visible' => ['required', 'boolean'], + ]); + + $photo->status = $validated['visible'] ? 'approved' : 'hidden'; + $photo->save(); + $photo->load('event')->loadCount('likes'); + + return response()->json([ + 'message' => 'Photo visibility updated', + 'data' => new PhotoResource($photo), + ]); + } + /** * Store a newly uploaded photo. */ @@ -397,6 +453,9 @@ class PhotoController extends Controller $assets = EventMediaAsset::where('photo_id', $photo->id)->get(); foreach ($assets as $asset) { + if (! is_string($asset->path) || $asset->path === '') { + continue; + } try { Storage::disk($asset->disk)->delete($asset->path); } catch (\Throwable $e) { @@ -412,7 +471,13 @@ class PhotoController extends Controller // Ensure legacy paths are removed if assets missing if ($assets->isEmpty()) { $fallbackDisk = $this->eventStorageManager->getHotDiskForEvent($event); - Storage::disk($fallbackDisk)->delete([$photo->path, $photo->thumbnail_path]); + $paths = array_values(array_filter([ + is_string($photo->path) ? $photo->path : null, + is_string($photo->thumbnail_path) ? $photo->thumbnail_path : null, + ])); + if (! empty($paths)) { + Storage::disk($fallbackDisk)->delete($paths); + } } $eventPackage = $event->eventPackage; diff --git a/playwright-report/data/2b972cf6fb2da3f16cadd7202702687cdeaa7901.webm b/playwright-report/data/2b972cf6fb2da3f16cadd7202702687cdeaa7901.webm deleted file mode 100644 index 95cc501..0000000 Binary files a/playwright-report/data/2b972cf6fb2da3f16cadd7202702687cdeaa7901.webm and /dev/null differ diff --git a/playwright-report/data/7a33d5db6370b6de345e990751aa1f1da65ad675.png b/playwright-report/data/7a33d5db6370b6de345e990751aa1f1da65ad675.png deleted file mode 100644 index 6d360f6..0000000 Binary files a/playwright-report/data/7a33d5db6370b6de345e990751aa1f1da65ad675.png and /dev/null differ diff --git a/playwright-report/data/b0493c4cccd959a8ecdb174bd08799b82fa8c840.webm b/playwright-report/data/b0493c4cccd959a8ecdb174bd08799b82fa8c840.webm deleted file mode 100644 index a0347bd..0000000 Binary files a/playwright-report/data/b0493c4cccd959a8ecdb174bd08799b82fa8c840.webm and /dev/null differ diff --git a/playwright-report/index.html b/playwright-report/index.html deleted file mode 100644 index 8b32ed0..0000000 --- a/playwright-report/index.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - -
- - - -