Skip to content

Commit

Permalink
fix UnlockedLabs#232: Implement EnrollmentState Enum and incorporat…
Browse files Browse the repository at this point in the history
…e in `Enrollment` Model and `StoreEnrollmentRequest`.
  • Loading branch information
chrissantillan committed Apr 29, 2024
1 parent 7a9352e commit 4e8dc02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/Enums/EnrollmentState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum EnrollmentState: string
{
case ACTIVE = 'active';
case INACTIVE = 'inactive';
// case INVITED = 'invited';
case COMPLETED = 'completed';
case DELETED = 'deleted';

public static function toArray(): array
{
return array_column(EnrollmentState::cases(), 'value');
}
}
4 changes: 3 additions & 1 deletion app/Http/Requests/StoreEnrollmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace App\Http\Requests;

use App\Enums\EnrollmentState;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreEnrollmentRequest extends FormRequest
{
Expand All @@ -26,7 +28,7 @@ public function rules(): array
return [
'user_id' => 'required|exists:users,id',
'course_id' => 'required|exists:courses,id',
'enrollment_state' => 'nullable|in:active,inactive,completed,deleted',
'enrollment_state' => [Rule::enum(EnrollmentState::class)],
'external_enrollment_id' => 'required|max:255',
'external_start_at' => 'required|date',
'external_end_at' => 'nullable|date|after_or_equal:provider_start_at',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Enrollment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Enums\EnrollmentState;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -26,6 +27,7 @@ class Enrollment extends Model
protected $casts = [
'external_start_at' => 'datetime',
'external_end_at' => 'datetime',
'enrollment_state' => EnrollmentState::class,
];

/**
Expand Down

0 comments on commit 4e8dc02

Please sign in to comment.