feat(tenant-admin): refresh event management experience
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Http\Requests\Tenant\EventStoreRequest;
|
||||
use App\Http\Resources\Tenant\EventResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\Photo;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
@@ -203,6 +204,75 @@ class EventController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function stats(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
if ($event->tenant_id !== $tenantId) {
|
||||
return response()->json(['error' => 'Event not found'], 404);
|
||||
}
|
||||
|
||||
$totalPhotos = Photo::where('event_id', $event->id)->count();
|
||||
$featuredPhotos = Photo::where('event_id', $event->id)->where('is_featured', true)->count();
|
||||
$likes = Photo::where('event_id', $event->id)->sum('likes_count');
|
||||
$recentUploads = Photo::where('event_id', $event->id)
|
||||
->where('created_at', '>=', now()->subDays(7))
|
||||
->count();
|
||||
|
||||
return response()->json([
|
||||
'total' => $totalPhotos,
|
||||
'featured' => $featuredPhotos,
|
||||
'likes' => (int) $likes,
|
||||
'recent_uploads' => $recentUploads,
|
||||
'status' => $event->status,
|
||||
'is_active' => (bool) $event->is_active,
|
||||
]);
|
||||
}
|
||||
|
||||
public function toggle(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
if ($event->tenant_id !== $tenantId) {
|
||||
return response()->json(['error' => 'Event not found'], 404);
|
||||
}
|
||||
|
||||
$activate = ! (bool) $event->is_active;
|
||||
$event->is_active = $activate;
|
||||
|
||||
if ($activate) {
|
||||
$event->status = 'published';
|
||||
} elseif ($event->status === 'published') {
|
||||
$event->status = 'draft';
|
||||
}
|
||||
|
||||
$event->save();
|
||||
$event->refresh()->load(['eventType', 'tenant']);
|
||||
|
||||
return response()->json([
|
||||
'message' => $activate ? 'Event activated' : 'Event deactivated',
|
||||
'data' => new EventResource($event),
|
||||
'is_active' => (bool) $event->is_active,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createInvite(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
if ($event->tenant_id !== $tenantId) {
|
||||
return response()->json(['error' => 'Event not found'], 404);
|
||||
}
|
||||
|
||||
$token = (string) Str::uuid();
|
||||
$link = url("/e/{$event->slug}?invite={$token}");
|
||||
|
||||
return response()->json([
|
||||
'link' => $link,
|
||||
'token' => $token,
|
||||
]);
|
||||
}
|
||||
public function bulkUpdateStatus(Request $request): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
@@ -30,7 +30,7 @@ class PhotoController extends Controller
|
||||
->firstOrFail();
|
||||
|
||||
$query = Photo::where('event_id', $event->id)
|
||||
->with(['likes', 'uploader'])
|
||||
->with('event')->withCount('likes')
|
||||
->orderBy('created_at', 'desc');
|
||||
|
||||
// Filters
|
||||
@@ -117,7 +117,7 @@ class PhotoController extends Controller
|
||||
list($width, $height) = getimagesize($file->getRealPath());
|
||||
$photo->update(['width' => $width, 'height' => $height]);
|
||||
|
||||
$photo->load(['event', 'uploader']);
|
||||
$photo->load('event')->loadCount('likes');
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Photo uploaded successfully. Awaiting moderation.',
|
||||
@@ -140,7 +140,7 @@ class PhotoController extends Controller
|
||||
return response()->json(['error' => 'Photo not found'], 404);
|
||||
}
|
||||
|
||||
$photo->load(['event', 'uploader', 'likes']);
|
||||
$photo->load('event')->loadCount('likes');
|
||||
$photo->increment('view_count');
|
||||
|
||||
return response()->json([
|
||||
@@ -177,7 +177,7 @@ class PhotoController extends Controller
|
||||
$photo->update($validated);
|
||||
|
||||
if ($validated['status'] ?? null === 'approved') {
|
||||
$photo->load(['event', 'uploader']);
|
||||
$photo->load('event')->loadCount('likes');
|
||||
// Trigger event for new photo notification
|
||||
// event(new \App\Events\PhotoApproved($photo)); // Implement later
|
||||
}
|
||||
@@ -222,6 +222,40 @@ class PhotoController extends Controller
|
||||
/**
|
||||
* Bulk approve photos (admin only)
|
||||
*/
|
||||
|
||||
public function feature(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 response()->json(['error' => 'Photo not found'], 404);
|
||||
}
|
||||
|
||||
$photo->update(['is_featured' => true]);
|
||||
$photo->refresh()->load('event')->loadCount('likes');
|
||||
|
||||
return response()->json(['message' => 'Photo marked as featured', 'data' => new PhotoResource($photo)]);
|
||||
}
|
||||
|
||||
public function unfeature(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 response()->json(['error' => 'Photo not found'], 404);
|
||||
}
|
||||
|
||||
$photo->update(['is_featured' => false]);
|
||||
$photo->refresh()->load('event')->loadCount('likes');
|
||||
|
||||
return response()->json(['message' => 'Photo removed from featured', 'data' => new PhotoResource($photo)]);
|
||||
}
|
||||
public function bulkApprove(Request $request, string $eventSlug): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
@@ -249,7 +283,7 @@ class PhotoController extends Controller
|
||||
// Load approved photos for response
|
||||
$photos = Photo::whereIn('id', $photoIds)
|
||||
->where('event_id', $event->id)
|
||||
->with(['uploader', 'event'])
|
||||
->with('event')->withCount('likes')
|
||||
->get();
|
||||
|
||||
// Trigger events
|
||||
@@ -321,7 +355,7 @@ class PhotoController extends Controller
|
||||
|
||||
$photos = Photo::where('event_id', $event->id)
|
||||
->where('status', 'pending')
|
||||
->with(['uploader', 'event'])
|
||||
->with('event')->withCount('likes')
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($request->get('per_page', 20));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user