Add approve-and-live action for Live Show
This commit is contained in:
@@ -30,7 +30,6 @@ class LiveShowPhotoController extends Controller
|
||||
|
||||
$query = Photo::query()
|
||||
->where('event_id', $event->id)
|
||||
->where('status', 'approved')
|
||||
->with('event')
|
||||
->withCount('likes');
|
||||
|
||||
@@ -89,6 +88,58 @@ class LiveShowPhotoController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function approveAndLive(LiveShowApproveRequest $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',
|
||||
'Photo not found',
|
||||
'The specified photo could not be located for this event.',
|
||||
Response::HTTP_NOT_FOUND,
|
||||
['photo_id' => $photo->id]
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array($photo->status, ['rejected', 'hidden'], true)) {
|
||||
return ApiError::response(
|
||||
'photo_not_eligible',
|
||||
'Photo not eligible',
|
||||
'Rejected or hidden photos cannot be approved for Live Show.',
|
||||
Response::HTTP_UNPROCESSABLE_ENTITY,
|
||||
['photo_id' => $photo->id]
|
||||
);
|
||||
}
|
||||
|
||||
if ($photo->status !== 'approved') {
|
||||
$photo->forceFill([
|
||||
'status' => 'approved',
|
||||
'moderated_at' => now(),
|
||||
'moderated_by' => $request->user()?->id,
|
||||
'moderation_notes' => null,
|
||||
])->save();
|
||||
}
|
||||
|
||||
$photo->approveForLiveShow($request->user());
|
||||
|
||||
if ($request->filled('priority')) {
|
||||
$photo->forceFill([
|
||||
'live_priority' => $request->integer('priority'),
|
||||
])->save();
|
||||
}
|
||||
|
||||
$photo->refresh()->load('event')->loadCount('likes');
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Photo approved and added to Live Show',
|
||||
'data' => new PhotoResource($photo),
|
||||
]);
|
||||
}
|
||||
|
||||
public function reject(LiveShowRejectRequest $request, string $eventSlug, Photo $photo): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
Reference in New Issue
Block a user