feat: smart assign person dialog with conflict details and assignable-persons endpoint
Add GET /events/{event}/shifts/{shift}/assignable-persons endpoint that
returns approved persons with availability status, conflict details, and
already-assigned flags. Improve ShiftAssignmentService conflict errors to
include section name, time slot, and time range. Replace both assign
dialogs with a new AssignPersonDialog featuring search, crowd type
filtering, availability toggle, and inline conflict warnings.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,12 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Enums\PersonStatus;
|
||||
use App\Enums\ShiftAssignmentStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\V1\BulkApproveShiftAssignmentRequest;
|
||||
use App\Http\Requests\Api\V1\RejectShiftAssignmentRequest;
|
||||
use App\Http\Resources\Api\V1\ShiftAssignmentResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\Person;
|
||||
use App\Models\Shift;
|
||||
use App\Models\ShiftAssignment;
|
||||
use App\Services\ShiftAssignmentService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -98,4 +101,72 @@ final class ShiftAssignmentController extends Controller
|
||||
|
||||
return $this->success($results);
|
||||
}
|
||||
|
||||
public function assignablePersons(Event $event, Shift $shift): JsonResponse
|
||||
{
|
||||
Gate::authorize('viewAny', [ShiftAssignment::class, $event]);
|
||||
|
||||
$festivalEventId = $event->parent_event_id ?? $event->id;
|
||||
$timeSlotId = $shift->time_slot_id;
|
||||
$shiftId = $shift->id;
|
||||
|
||||
// Get all conflict assignments for this time slot in one query
|
||||
$conflicts = ShiftAssignment::where('time_slot_id', $timeSlotId)
|
||||
->whereIn('status', [
|
||||
ShiftAssignmentStatus::PENDING_APPROVAL,
|
||||
ShiftAssignmentStatus::APPROVED,
|
||||
])
|
||||
->with(['shift.festivalSection', 'shift.timeSlot'])
|
||||
->get()
|
||||
->keyBy('person_id');
|
||||
|
||||
// Get all assignments for THIS shift in one query
|
||||
$alreadyAssigned = ShiftAssignment::where('shift_id', $shiftId)
|
||||
->whereNotIn('status', [
|
||||
ShiftAssignmentStatus::REJECTED,
|
||||
ShiftAssignmentStatus::CANCELLED,
|
||||
])
|
||||
->pluck('person_id')
|
||||
->flip();
|
||||
|
||||
$persons = Person::where('event_id', $festivalEventId)
|
||||
->where('status', PersonStatus::APPROVED)
|
||||
->with('crowdType')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(function (Person $person) use ($conflicts, $alreadyAssigned, $shiftId) {
|
||||
$isAlreadyAssigned = $alreadyAssigned->has($person->id);
|
||||
$conflict = $conflicts->get($person->id);
|
||||
$hasConflict = $conflict && $conflict->shift_id !== $shiftId;
|
||||
|
||||
return [
|
||||
'id' => $person->id,
|
||||
'name' => $person->name,
|
||||
'email' => $person->email,
|
||||
'status' => $person->status,
|
||||
'crowd_type' => $person->crowdType ? [
|
||||
'id' => $person->crowdType->id,
|
||||
'name' => $person->crowdType->name,
|
||||
'system_type' => $person->crowdType->system_type,
|
||||
] : null,
|
||||
'is_available' => ! $hasConflict && ! $isAlreadyAssigned,
|
||||
'already_assigned' => $isAlreadyAssigned,
|
||||
'conflict' => $hasConflict ? [
|
||||
'section_name' => $conflict->shift->festivalSection->name,
|
||||
'shift_title' => $conflict->shift->title ?? $conflict->shift->festivalSection->name,
|
||||
'time_slot_name' => $conflict->shift->timeSlot->name,
|
||||
'time' => $conflict->shift->timeSlot->start_time
|
||||
. '–' . $conflict->shift->timeSlot->end_time,
|
||||
] : null,
|
||||
];
|
||||
})
|
||||
->sortBy([
|
||||
['already_assigned', 'asc'],
|
||||
['is_available', 'desc'],
|
||||
['name', 'asc'],
|
||||
])
|
||||
->values();
|
||||
|
||||
return response()->json(['data' => $persons]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user