feat: shift assignment workflow with claim, approve, reject, cancel, and bulk approve

Implements the complete ShiftAssignment lifecycle:
- ShiftAssignmentStatus enum with allowed transitions
- ShiftAssignmentService with claim/assign/approve/reject/cancel/bulkApprove
- ShiftAssignmentController with event-scoped endpoints
- ShiftAssignmentPolicy (organizer + volunteer self-cancel)
- VolunteerAvailability model, controller, and sync endpoint
- Refactored ShiftController to delegate to service layer
- 31 workflow tests covering all paths and multi-tenancy

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 17:00:56 +02:00
parent 303280286f
commit 0cdc192239
21 changed files with 1830 additions and 77 deletions

View File

@@ -76,6 +76,11 @@ final class Person extends Model
return $this->hasMany(ShiftAssignment::class);
}
public function volunteerAvailabilities(): HasMany
{
return $this->hasMany(VolunteerAvailability::class);
}
public function identityMatches(): HasMany
{
return $this->hasMany(PersonIdentityMatch::class);

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Models;
use App\Enums\ShiftAssignmentStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
@@ -99,7 +100,7 @@ final class Shift extends Model
return (int) $this->attributes['filled_slots'];
}
return $this->shiftAssignments()->where('status', 'approved')->count();
return $this->shiftAssignments()->where('status', ShiftAssignmentStatus::APPROVED)->count();
});
}

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\Models;
use App\Enums\ShiftAssignmentStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -36,11 +38,14 @@ final class ShiftAssignment extends Model
protected function casts(): array
{
return [
'status' => ShiftAssignmentStatus::class,
'auto_approved' => 'boolean',
'assigned_at' => 'datetime',
'approved_at' => 'datetime',
'checked_in_at' => 'datetime',
'checked_out_at' => 'datetime',
'hours_expected' => 'decimal:2',
'hours_completed' => 'decimal:2',
];
}
@@ -58,4 +63,37 @@ final class ShiftAssignment extends Model
{
return $this->belongsTo(TimeSlot::class);
}
public function assignedByUser(): BelongsTo
{
return $this->belongsTo(User::class, 'assigned_by');
}
public function approvedByUser(): BelongsTo
{
return $this->belongsTo(User::class, 'approved_by');
}
public function scopeActive(Builder $query): Builder
{
return $query->whereIn('status', [
ShiftAssignmentStatus::PENDING_APPROVAL,
ShiftAssignmentStatus::APPROVED,
]);
}
public function scopeForStatus(Builder $query, ShiftAssignmentStatus $status): Builder
{
return $query->where('status', $status);
}
public function isCancellable(): bool
{
return $this->status->canTransitionTo(ShiftAssignmentStatus::CANCELLED);
}
public function isApprovable(): bool
{
return $this->status->canTransitionTo(ShiftAssignmentStatus::APPROVED);
}
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
final class VolunteerAvailability extends Model
{
use HasFactory;
use HasUlids;
public $timestamps = false;
protected $table = 'volunteer_availabilities';
protected $fillable = [
'person_id',
'time_slot_id',
'preference_level',
'submitted_at',
];
protected function casts(): array
{
return [
'preference_level' => 'integer',
'submitted_at' => 'datetime',
];
}
public function person(): BelongsTo
{
return $this->belongsTo(Person::class);
}
public function timeSlot(): BelongsTo
{
return $this->belongsTo(TimeSlot::class);
}
}